dcsimg
what's the factory?
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   zhebin_cong
Posted On:   Friday, January 25, 2002 01:23 AM

hello
as we can seen,there are a lot of "factory" in the java,such as InitialContextFactory,KeyManagerFactory,.........
so many factories have confused me,but i think there must be some common meaning withing the factories,and there must be differences between the factories and other classes,who can help me?

thank you

Re: what's the factory?

Posted By:   Luigi_Viggiano  
Posted On:   Friday, January 25, 2002 07:02 AM

A factory is a class or a method that lets you to create different kind of objects implementing the same interface. The implementation is not necessary the same, and could also be unknown at compilation time.
This let the client code (using the factory and created objects) to be losely coupled with the real implementations of the interface.
When the factory returns a different implementation, the rest of the code doesn't change.

Re: what's the factory?

Posted By:   Dermot_Hennessy  
Posted On:   Friday, January 25, 2002 01:55 AM

A factory is a class which implements the factory pattern.

A Factory pattern is one that returns an instance of one of several possible classes depending on the data provided to it. Usually all of the classes it returns have a common parent class and common methods, but each of them performs a task differently and is optimized for different
kinds of data. See
the Pattern Depot Website for an online PDF book on patterns and their usage in Java.

Dermot

About | Sitemap | Contact