aspose file tools*
The moose likes Architect Certification (SCEA/OCMJEA) and the fly likes Simple Factory vs Factory method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Architect Certification (SCEA/OCMJEA)
Bookmark "Simple Factory vs Factory method" Watch "Simple Factory vs Factory method" New topic
Author

Simple Factory vs Factory method

B.Sathish
Ranch Hand

Joined: Aug 18, 2005
Posts: 372
I have question related to chapter 4 (Baking with OO goodness) - the factory pattern.

My question is what are the advantages offered by the Factory method pattern over the Simple Factory programming idiom? Why do we need Factory method when we have the Simple Factory idiom?

My argument is that the Simple Factory idiom is based on composition and delegation while the Factory method is based on inheritance. After reading the first 3 chapters, it is obvious that we should favor composition over inheritance due its advantages (dynamic behavior changes and flexibility). This being the case why need to use the Factory method pattern? What is it that you can do with the Factory method that you cannot do with the Simple Factory more flexibly and dynamically?

The book says that the Factory method pattern localizes the factory (the factory method) and the client (calling method) to the same class and hence the same framework and you can enforce tighter control on the client by making the client method final. These arguments are somehow not that appealing to me. Also with the Simple Factory, you can compose a Factory interface and delegate the call at run-time to any concrete factory class implementing that interface. This is more dynamic and flexible than having the factory implementation in a sub-class

Would like to know your views on this.
B.Sathish
Ranch Hand

Joined: Aug 18, 2005
Posts: 372
I was referring to the Head First Design patterns book. If you are not a reader of that book, its ok, just ignore the first line in my post and start reading from the second
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Simple Factory vs Factory method