设计模式例程
This commit is contained in:
50
inc/simple_factory.hpp
Normal file
50
inc/simple_factory.hpp
Normal file
@ -0,0 +1,50 @@
|
||||
#pragma once
|
||||
#include "common.hpp"
|
||||
|
||||
typedef enum // <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
{
|
||||
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;
|
||||
};
|
Reference in New Issue
Block a user