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 ]
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?
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Joined: Jun 26, 2002
thanks Ilja, i am still trying hard to make it sense to me.hopefully i will get it over.
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.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi