
设计模式
a553455
Whatever makes you unhappy,fuck it.
展开
-
C++ 结构性设计模式文字总结 Structural Design Patterns
Adapter 适配器问题: 有一个方形钉子和一个圆形的洞,想把方形钉子插入圆形的洞怎么办?解决方案:创造一个适配器,继承圆形钉子,这样此适配器可以放入圆形的洞。适配器用方形钉子作为参数,创造出圆形钉子。这样方形钉子可以放入适配器中,适配器可以放入圆形洞中,完成了适配。Bridge 桥梁问题: 有一些电视,有一些遥控器,如何让每个遥控器都可以随便控制哪个电视?解决方案:使所...原创 2020-02-16 16:30:34 · 287 阅读 · 0 评论 -
C++ Decorator 装饰者模式 简单代码
一、代码#include <iostream>#include <string>using namespace std;class IBase{public: virtual void outdata(string message) = 0;};class Base :public IBase{public: void outdat...原创 2020-02-15 15:39:07 · 136 阅读 · 0 评论 -
C++ 工厂模式 Factory代码例子
一、UML图二、代码#include <iostream>using namespace std;class HotDrinkClass {public: virtual void prepare() = 0;};class Tea :public HotDrinkClass{public : void prepare() override { cout &...原创 2020-02-13 16:02:35 · 438 阅读 · 0 评论 -
C++ 单例模式 singleton 两种简单方法
第一种是最符合直觉用指针的方法class single{private: static single* ptrthis; string myname; single() { myname = "single"; } friend ostream& operator<<(ostream& os,single* ptr) { return os &...原创 2020-02-12 21:27:04 · 372 阅读 · 1 评论 -
C++ 开闭原则代码例子 Open/Closed Principle
// Open-closed Principle// entities should be open for extension, but closed for modification#include <iostream>#include <string>#include <vector>enum class Color { Red, Green...原创 2020-02-11 17:37:59 · 527 阅读 · 1 评论