Files
design-pattern/inc/simple_factory.hpp
2025-06-02 13:57:29 +08:00

51 lines
709 B
C++
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#pragma once
#include "common.hpp"
typedef enum // ť­ąĘŔŕĐÍ
{
PenTypeLine = 1,
PenTypeRect = 2,
PenTypeEllipse = 3
}PenType;
class Pen
{
public:
Pen(string name);
virtual PenType getType() = 0;
string getName();
private:
string m_name;
};
class LinePen :public Pen
{
public:
LinePen(string name) :Pen(name) {}
PenType getType();
};
class RectanglePen :public Pen
{
public:
RectanglePen(string name) :Pen(name) {}
PenType getType();
};
class EllipsePen :public Pen
{
public:
EllipsePen(string name) :Pen(name) {}
PenType getType();
};
class PenFactory
{
public:
PenFactory() {};
Pen* CreatePen(PenType pentype);
private:
map<PenType, Pen*> m_PenProduct;
};