This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with the problem Creational Pattern solves

 
Tulsi Rai
Ranch Hand
Posts: 55
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
Every creational pattern states that
Sometimes, an Application (or framework) at runtime, cannot anticipate the class of object that it must create. The Application (or framework) may know that it has to instantiate classes, but it may only know about abstract classes (or interfaces), which it cannot instantiate. Thus the Application class may only know when it has to instantiate a new Object of a class, not what kind of subclass to create.


I am having problem particularly with the statement "....can not anticipate the class of object that it must create, may only know when it has to instantiate a new object of a class ,not what kind of subclass to create...."

why can't we anticipate the class of object that's going to be created? could you please give me some real world example in easy-to-undestand way?
thanks.
[ August 18, 2004: Message edited by: t ray ]
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think this description is a little bit, well, besides the point.

The point, to me, is that the patterns decouple the when from the what. That is you can have one part of the application decide what classes to instanciate (by creating the appropriate factory or something) and another part of the application decide when to instanciate them.

Does that help?
 
Tulsi Rai
Ranch Hand
Posts: 55
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Ilja, i am still trying hard to make it sense to me.hopefully i will get it over.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm just this minute working on a factory that gets a map of keys and classnames from configuration. When somebody asks for a handler for some input object the factory looks up a classname with a key from the input and creates a new handler. This lets us add new handlers without recompiling the object that's using them. Good clean fun.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic