Hi All,
I am studying design patterns and create a program for "Factory Pattern ".
I have read various tutorials and create my own with the help of it.
I just need your comments that whether this implementation is correct or it can be made
accurate according to Factory pattern.
Its running fine and values are hard coded for time being.Code:#include<iostream> using namespace std; class Pizza { public: virtual void displayPrice() = 0; }; class MacDonald : public Pizza { public: int m_price; MacDonald() {} MacDonald( int price ) { m_price = price; } void displayPrice() { cout<<"The Rate of MacDonald Pizza is "<<120; } }; class HotMillion : public Pizza { public: int m_price; HotMillion(){} HotMillion(int price ) { m_price = price; } void displayPrice() { cout<<"The Rate of HotMillion Pizza is "<<200; } }; class Factory { public: int m_index; Factory(int index) { m_index = index; } Pizza* show() { switch( m_index ) { case 1: new MacDonald; break; case 2: new HotMillion; break; } } }; int main() { Factory a( 1 ); Pizza *p = a.show(); p->displayPrice(); }
Please give your valuable suggestion.
Thanks



LinkBack URL
About LinkBacks



