A factory is responsible for creating new instances of "something".
Factories are commonly used in the implementation of
Adapteradapters .
Note that while the interfaces for adapters and factories are nearly the
same, the two don't do quite the same thing. Whereas an adapter is intended
to be associated with a
Container through the use of a
org.jicarilla.lang.Selector and is not required to always
return a new instance from its
Adapter.getInstance method, the
factory must always return a new instance on every call to its
Factory.newInstance() method, and is never directly associated with a
container.
If you do wish to add a factory implementation to a container, you should
use one of
org.jicarilla.containers.adapters several available to
wrap the factory.
Note that it is usually quite possible to use a factory without using an
adapter or a container. When you do, observe these contracts:
- method call ordering. You may not call
releaseInstance() until you have called
newInstance() at least once.
- method call pairing. You should call
releaseInstance() once for every time you call
newInstance() , and the parameter to
releaseInstance() must be the object you received
from newInstance() .
(note that it is legal to call newInstance()
multiple times in a row and then call releaseInstance()
multiple times in a row.)
Also note that some Factory implementations may be less
strict about these rules. See the documentation for those implementations
to be sure.
author: Leo Simons version: $Id: Factory.java,v 1.4 2004/03/23 13:37:51 lsimons Exp $ |