Hi, I am not new to patterns, I have used them over the last few years quite a bit. However, I am not sure what is the real difference between the Abstract Factory and Factory method is. It sounds like Abstract Factory could have a factory method. The Concrete Factory can implement the factory method. I guess when the Abstract Factory has a factory method,it may also have additional functionality, so it may not be just an Abstract Factory. Am I understanding this correctly? Thanks, Aruna
The factory method is defined in a base class or interface and the subclass returns an instance of the Object. The abstract factory returns a FACTORY that can return a FAMILY of objects. Often patterns get mixed together and it becomes difficult to distinguish between them. I find this particularly true of the FactoryPatterns as often one factory may have several of the patterns in it. Example of Factory Method: Note only a Button is returned (i.e not a Factory)
Example of an Abstract Factory: Note a only a Button is returned. Note that GUIFactory is returned with a Factory method! Note the other methods like createButton() are not factory method in this case as they are not being created by the Button class themselves.
Let me try this again. This time trying to remove stupid mistakes. Example of an Abstract Factory: Note a whole Factory is returned via createInstance(). In the factory method design pattern an Object is returned (a button in the example above), not a Factory. It gets a little confusing though in that GUIFactory is returned via createInstance() which is a Factory method! Note createButton() is not a factory method as the returned Button is not being created by the Button subclasses, but by the Factory.
Your interpretation sounds wrong. The difference is sutble. Factory method is just responsible to create an object. Just that object.
But Abs.Factory defines an interface to create families of related or dependent objects. So Abs.Fact defines several Factory methods where as the Factory method pattern just limits itself to a specifc kind of object.
Correct me If I'm worng.
Thanks,<br />Bhanu<br />SCEA Step-I<br />SCBCD for J2EE 1.3<br />SCJP1.4