• 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
  • paul wheaton
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • Mikalai Zaikin
  • Himai Minh

Design Patterns Factory Method example

 
Ranch Hand
Posts: 176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The following is an example of Factory Method :

createDocument() is the factory method and I can have another class MyAnotherDocument2 and then in the MyApplication class create an object of MyAnotherDocument2 and return it.
This is the meaning of the defn :

Factory Method (createDocument() here )defines an interface for creating an object, but let subclasses (MyApplication) decide which class to instantiate.

Please provide comments on my understanding. Thanks
 
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Looks alright to me but I guess u want a further elaboration
on this and so do I, maybe Mr.Wetherbie can comment on this.
Thanks
 
Rancher
Posts: 1449
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The example looks pretty similar to the example they use in the Design Patterns book.
I think your understanding of what is going on is correct. Remember that the alternate name for factory (and the name that I knew it by first) is virtual constructor.
I'm not if what I wote is helpful or not. I'm sure you'll let me know.
John
 
Madhu Juneja
Ranch Hand
Posts: 176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What you write here is always very much helpful. Thanks.
 
I AM MIGHTY! Especially when I hold this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic