• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Simple Factory vs Factory method

 
Ranch Hand
Posts: 372
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 372
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm stuck on the same problem. I know this is a way old thread, but can someone clear the differences between the 2 patterns here?
 
The moth suit and wings road is much more exciting than taxes. Or this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic