I work through the book "First Design Samples".
I believe that I understand the simple factory and factory method, but it's hard for me to understand what advantages the simple factory method brings.
If Object A uses a simple factory to create its B-objects, clients can create it as follows:
A a = new A(new BFactory());
whereas if the object uses the factory method, the client can create it as follows:
A a = new ConcreteA();
So, in the case of a simple factory, clients make up A with B factory, while using the factory method, the client selects the appropriate subclass for the types of B that he wants.
It seems that there really is not much choice between them. Either you need to choose which BFactory you want to build A with, or you need to choose the correct subclass of A to give you Bs.
?
!
: . - , Head First, factory factory, ( .119), " [] factory , : -". -, , -, - .
factory, bake() . factory, , .
, , Head First factory factory, .