Forums Register Login

Stateless Functions

+Pie Number of slices to send: Send
In order to login a user to our web-site we have a method
public User authenticate(String id, String password);
i.e. it authenticates a User and returns a populated User object otherwise it returns null.
This method is recieved by a JSP which authenticates the User and forward the USer to another JSP.
Now, should the method be static ?
OR
Should the class be Singleton ?
OR
Should the class have Application Scope i.e.
<jsp:useBean class="Authenticate" scope="Application" />
OR
Should we create a new object of the class everytime?
+Pie Number of slices to send: Send
Go with either a singleton or a static method.
To decide between them ask yourself the following:
  • Is the class keeping any state?
  • Will there possibility be a need for more than one instance?
  • Will the class need to extend another class or be extended in the future?
  • Do you need to contol when the class is loaded into memory?


  • If the answer to all of these is no than you are best off going with a static final method as the Singleton pattern is not going to offer any benefits.
    Either way you go, if this is to be used from a JSP then I would wrap it with a custom tag.
    [ September 15, 2002: Message edited by: Chris Mathews ]
    +Pie Number of slices to send: Send
    Thanks for the reply, Chris.
    Whats wrong with using a bean with application scope. It will be same as Singleton.
    If we wrap the class with custom tags, it will be same as creating a new bean everytime. So last approach is also correct ?
    Can you really tell me that we aren't dealing with suspicious baked goods? And then there is this tiny ad:
    a bit of art, as a gift, that will fit in a stocking
    https://gardener-gift.com


    reply
    reply
    This thread has been viewed 472 times.
    Similar Threads
    Servlet Security/Authentication question
    User validation
    JAAS client problem in mastering EJB
    Returning an object or null
    Don't understand defining roles in HFJS book
    More...

    All times above are in ranch (not your local) time.
    The current ranch time is
    Mar 28, 2024 18:09:52.