设计模式例程

This commit is contained in:
2025-06-02 13:57:29 +08:00
commit 22124bb827
32 changed files with 2149 additions and 0 deletions

79
inc/abstract_factory.hpp Normal file
View File

@ -0,0 +1,79 @@
#pragma once
#include "common.hpp"
class Shape // <20><>״<EFBFBD>ӿ<EFBFBD>
{
public:
virtual void draw() = 0;
};
class Rectangle :public Shape
{
public:
void draw();
};
class Square :public Shape
{
public:
void draw();
};
class Circle :public Shape
{
public:
void draw();
};
class Color // <20><>ɫ<EFBFBD>ӿ<EFBFBD>
{
public:
virtual void fill() = 0;
};
class Red :public Color
{
public:
void fill();
};
class Green :public Color
{
public:
void fill();
};
class Yellow :public Color
{
public:
void fill();
};
class AbstractFactory
{
public:
virtual Color* getColor(string color) = 0;
virtual Shape* getShape(string shape) = 0;
};
class ShapeFactory :public AbstractFactory
{
public:
Shape* getShape(string shape);
Color* getColor(string color);
};
class ColorFactory :public AbstractFactory
{
public:
Shape* getShape(string shape);
Color* getColor(string color);
};
class FactoryProducer
{
public:
AbstractFactory* getFactory(string choice);
};