class shape
{
public:
shape() {};
~shape() {};
virtual void draw() = 0;
};
class square : public shape
{
public:
square() {};
~square() {};
void draw()
{
cout << "square is drawn\n" << endl;
}
};
class circle : public shape
{
public:
circle() {};
~circle() {};
void draw()
{
cout << "circle is drawn\n" << endl;
}
};
int main()
{
shape* pShape = (circle*)new circle();
pShape->draw();
return 1;
}
http://www.javacamp.org/designPattern/factory.html
http://en.wikipedia.org/wiki/Factory_method_pattern
'Papers > Design pattern' 카테고리의 다른 글
Flyweight pattern (0) | 2007.12.18 |
---|---|
Delegation pattern (0) | 2007.09.29 |
adapter pattern (0) | 2007.09.29 |
visitor pattern (0) | 2007.09.02 |
singleton pattern (0) | 2007.07.07 |