> >If this was written as an application (instead of a servlet), then I
could
> >do this using the 'Singleton' design pattern, and create a single
instance
> >of a class.  Or as static methods and variables of a class.  But this
won't
> >work for a servlet, because what's really needed is one instance for each
> >'request/session' that is being processed.
You could not do this if the application object in question was being used
by multiple threads.
Servlets are not a totally new programming paradigm but they do introduce
paradigms that
people are often not familiar with. In particular, multi-thread
client/server programming.
Forget that what your trying to do will live in a servlet and think about
the business logic
in the context of a multi-thread environment where the threads correspond to
independent
interaction with the business object and each thread has state external to
the business object.
This is the environment of a servlet.

...
> >I don't think this is elegant, because I'd still have to pass an instance
> >of that object to every object/method that might need to get some
> >information.  There doesn't seem to be a global way to get it.  This also
> >means that many of my methods wouldn't even directly use the object, but
> >would have to carry that handle around as a parameter anyway, in case the
> >lower level methods need it.
> >
> >Imagine, for example, if every method you write in any Java application
> >would need to have "System.out" passed to it, in case there is some
method
> >that might need to print to the terminal.
> >
You are trying to access object through your singleton that have very
different life
cycles. Logging and database connections have lifecycles that span multiple
servlets
and can be used via singletons. They have a meaningful state and existence
independent
of a given servlet. This is why System.out is presented as a singleton.

Authentication information is passed in every time by the client and so is a
property of the
current request. Since this is external state, business object that directly
or indirectly
operate based on this info have to be given the info. So, you either pass it
in as an argument
to the relevant methods or you create a new business object for each request
and bind the
request state to instance variables of the business object.




***********************************************************************
Bear Stearns is not responsible for any recommendation, solicitation,
offer or agreement or any information about any transaction, customer
account or account activity contained in this communication.
***********************************************************************

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to