I worked with java code that supposedly uses the Factory pattern, but I'm not completely convinced of the pattern.
My code does this:
// the factory class SomeFactoryImpl { Set<SomeClass> getSomeListOfObjects(); }
And somewhere in the code:
{ ... SomeFactory factory = new SomeFactoryImpl(); Set<SomeClass> list = factory.getSomeListOfObjects(); }
What I'm thinking about, if Factory classes do not have a static create () method, then you need to create a factory instance, which IMO should be as complex as creating an instance of the object itself.
I do not consider it an argument that such a Factory can return collections of created objects, is good enough. I believe there may be cleaner workarounds if you need to create a Factory instance before actually creating objects from the factory.
I feel that it is better if the create method is a static method of the Factory class. But I am also sure that my opinion is not entirely βright.β
SO , Factory , ?
, , : FactoryMethodPattern, FactoryMethod CreationMethod .
factory .
,
:
public ThisClass(SomeFactory someFactory) { this.factory = someFactory; }
...
{ ... Set<SomeClass> list = factory.getSomeListOfObjects(); }
, ...
, - , , factory . , ( ).
, factory ( ...), , , factory -Instance .
, factory, :
" objet, , . factory ."
, , SomeFactoryImpl , - . , , , , . , swing, , VM. JPanel, , , , , factory factory ( JPanel, ). , . (, wikipedia, ) factory, , factory , " ", .
SomeFactoryImpl
, , , . , , , factory , .
- , , ( , ), . istantiate objects.. - ( ).
factory
RedWidgetFactory
BlueWidgetFactory
IMO, , , GoF Factory, . , GoF (SomeFactory, SomeFactoryImpl) (SomeClass), .
API, , , , , . :
# 1, JDBC, :
Driver
Connections
Statements
DriverManager
( DriverManager , getConnection(...), ).
getConnection(...)
, , , JDBC,
new OracleDriver().connect(...)
, , factory.
, , , .
, .