![]() |
| ||
| Factory design pattern I have this class: class Pizza{ And one of its subclass: class Small: public Pizza{ Besides the "Small" class there are others that are similar, eg. "Medium", "Large", etc. I want to implement a Factory class for this. However, it doesnt seem to work: class PizzaFactory: public Pizza{ I wonder why when i called in main, it does not give me error but the "id" parameter does not get included into the switch statement. Any help would be much appreciated. |
| ||
| Re: Factory design pattern There is nothing wrong with your code except " class PizzaFactory: public Pizza{". You don't need to derive factory class from base class. Although this would not cause any fatal problems.Post your main and the some more description of the problem. |
| ||
| Re: Factory design pattern Quote:
The reason i derive factory class from base class is because i want to call the member function of class Pizza directly. The idea of this is simple. I have class Pizza, its derived classes such as Small, Medium, Large. Now that i want to have a Factory class so that by calling this Factory Class a certain derived class (Small, for instance) will be created, instead of creating new instance by calling directly Small. Main is as follow: int main(){ It does not give any error but the pizza created is a pizza of type Pizza (generic) and not that of Small, which should have been the one since i call getPizzaINstance(1). What am i missing? Thanks |
| ||
| Re: Factory design pattern I think i got this one. I'll see if anything else coming up. |
| ||
| Re: Factory design pattern So the problem is with main() and not those classes.. Again you shouldn't derive factory from the base.. it's against the pattern.. Change the main() to: int main(){ |
| All times are GMT -4. The time now is 6:31 pm. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC