who can give me a example in C++ using Factory Pattern
-
I am learning Design Pattern and who can give me a easy example I write some demo but I think they are not good so I wanna get some good one that can make me understand the pattern better. Thanks a lot!~ ;)
This is a meaningless question. Which pattern ? I suggest buying a good book and reading on both patterns, and their examples.
Christian Graus No longer a Microsoft MVP, but still happy to answer your questions.
-
I am learning Design Pattern and who can give me a easy example I write some demo but I think they are not good so I wanna get some good one that can make me understand the pattern better. Thanks a lot!~ ;)
-
Check this link. I hope this will help you. http://www.codeguru.com/forum/showthread.php?t=327982[^]
-
This is a meaningless question. Which pattern ? I suggest buying a good book and reading on both patterns, and their examples.
Christian Graus No longer a Microsoft MVP, but still happy to answer your questions.
One more question
Product //abstract Creator //abstract
+Method() +FactoryMethod()
| |
| |
| |
ConcreteProduct<-------------ConcreteCreator
+Method() +FactoryMethod()-----return new ConcreteProductIn the demo code of Factory Pattern they use
return
to new a ConcreteProduct objectFactory* fac = new ConcreteFactory(); Product* p = fac->CreateProduct();
what about using a member variabal of Creator to control Creator's behavior like:Product* p = new CreateProduct(); //use p to initialize member variable Product* _p; Factory* fac = new ConcreteFactory(p);
and use like "fac->_p->method()" to call different subclass member funtion is it good or not to use a abstract class object as member variabal to control its behavior ???:confused: