Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Design Patterns Factory Method example

 
Madhu Juneja
Ranch Hand
Posts: 176
  • Mark post as helpful
  • send pies
  • 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
 
Walter Vetrivel
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • 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
 
John Wetherbie
Rancher
Posts: 1449
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
What you write here is always very much helpful. Thanks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic