![](https://img-blog.csdnimg.cn/20201014180756916.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
c++
文章平均质量分 82
Claude_Qin
这个作者很懒,什么都没留下…
展开
-
23种设计模式之单例模式(创建型,3 Singleton,c++实现)
1 恶汉式#include <iostream>using namespace std;class Singleton {private:Singleton() {cout << "I am singleton object" << endl;}public:static Singleton* getInstance() {return __singleton;...原创 2018-02-26 12:49:35 · 142 阅读 · 0 评论 -
23种设计模式之工厂模式(创建型,1 Factory,c++实现)
1 简单工厂模式#include <stdlib.h>#include <stdio.h>#include <iostream>using namespace std;class Fruit {public:virtual void sayName() = 0;};class Banana :public Fruit {public:void sayName()...原创 2018-02-25 13:39:45 · 121 阅读 · 0 评论 -
23种设计模式之抽象工厂模式(创建型,2 AbstractFactory,c++实现)
#include <stdlib.h>#include <stdio.h>#include <iostream>using namespace std;class Fruit {public:virtual void sayName() = 0;};class SouthBanana :public Fruit {public:void sayName() {c...原创 2018-02-25 20:04:46 · 199 阅读 · 0 评论 -
23种设计模式之策略模式(行为型,4 Strategy,c++实现)
代码实现:#include <iostream>using namespace std;class Strategy{public:virtual void crypt() = 0;};class DES : public Strategy{public:virtual void crypt(){cout << "DES crypt" << endl;}};cl...原创 2018-03-18 12:26:11 · 133 阅读 · 0 评论 -
23种设计模式之中介者模式(行为型,5 Mediator,c++实现)
代码实现:#include <iostream>#include <string>using namespace std;class Mediator;class Person{public:Person(string name, int sex, int condition, Mediator* mediator){this->name = name;this-&g...原创 2018-03-18 13:30:02 · 145 阅读 · 0 评论 -
23种设计模式之观察者模式(行为型,6 Observer,c++实现)
代码实现:#include <iostream>#include <string>#include <list>using namespace std;class Secretary;class PlayerObserver{public:PlayerObserver(Secretary* secretary){this->secretary = secr...原创 2018-03-18 18:13:10 · 141 阅读 · 0 评论 -
23种设计模式之备忘录模式(行为型,7 Memento,c++实现)
代码实现:#include <iostream>#include <string>using namespace std;class PersonMemento{public:PersonMemento(string name, int age){this->name = name;this->age = age;}void setName(string nam...原创 2018-03-18 20:12:00 · 199 阅读 · 0 评论 -
23种设计模式之访问者模式(行为型,8 Visitor,c++实现)
代码实现:#include <iostream>#include <string>#include "list"using namespace std;class Visitor;class ParkElement{public:virtual void accept(Visitor* visitor) = 0;};class Visitor{public:virtual ...原创 2018-03-24 18:32:45 · 174 阅读 · 0 评论 -
23种设计模式之状态模式(行为型,9 State,c++实现)
#include <iostream>#include <string>using namespace std;class Worker;class State{public:virtual void doSomething(Worker* worker) = 0;};class Worker{public:Worker();void doSomething(){curre...原创 2018-03-24 21:35:31 · 234 阅读 · 0 评论 -
23种设计模式之解释器模式(行为型,10 Interpreter,c++实现)
代码实现:#include <iostream>#include <string>using namespace std;class Context {public:Context(){this->setNum(0);}void setNum(int num){this->num = num;}int getNum(){return this->num;}...原创 2018-03-25 12:22:12 · 230 阅读 · 0 评论 -
23种设计模式之原型模式(创建型,5 Prototype,c++实现)
代码实现:#define _CRT_SECURE_NO_WARNINGS#include <iostream>#include <string>using namespace std;class Person{public:virtual Person* clone() = 0;virtual void print() = 0;};class CPPProgrammer :...原创 2018-03-04 12:19:32 · 159 阅读 · 0 评论 -
23种设计模式之适配器模式(结构型,3 Adapter,c++实现)
代码实现:#include <iostream>using namespace std;class Current220v{public:void useCurrent220v(){cout << "use current 220 v" << endl;}};class Current18v{public:virtual void useCurrent18v()...原创 2018-03-04 17:53:22 · 163 阅读 · 0 评论 -
23种设计模式之装饰器模式(结构型,2 Decorator,c++实现)
代码实现:#include <iostream>using namespace std;class Car{public:virtual void show() = 0;};class RunCar :public Car{public:void show(){cout << "run" << endl;}};class SwimCarDirector :pub...原创 2018-03-04 17:21:22 · 176 阅读 · 0 评论 -
23种设计模式之建造者模式(创建型,4 Builder,c++实现)
代码实现:#include <iostream>#include <string>using namespace std;class House {public:void setDoor(string door) {this->door = door;}void setWall(string wall) {this->wall = wall;}void setW...原创 2018-02-27 10:45:57 · 168 阅读 · 0 评论 -
23种设计模式之桥接模式(结构型,4 Bridge,c++实现)
代码实现:#include <iostream>using namespace std;class Engine{public:virtual void installEngine() = 0;};class Engine4400C : public Engine{public:virtual void installEngine(){cout << "install En...原创 2018-03-10 16:52:32 · 182 阅读 · 0 评论 -
23种设计模式之组合模式(结构型,5 Composite,c++实现)
代码实现:#include <iostream>#include <list>#include <string>using namespace std;class IFile{public:virtual void display() = 0;virtual int add(IFile*) = 0;virtual int remove(IFile*) = 0;v...原创 2018-03-10 17:20:39 · 187 阅读 · 0 评论 -
23种设计模式之外观模式(结构型,6 Facade,c++实现)
代码实现:#include <iostream>#include <list>#include <string>using namespace std;class SubsystemA{public:void doThing(){cout << "SubsystemA do thing" << endl;}};class Subsyste...原创 2018-03-10 19:20:42 · 243 阅读 · 0 评论 -
23种设计模式之享元模式(结构型,7 Flyweight,c++实现)
代码实现:#include <iostream>#include <list>#include <string>#include <map>using namespace std;class Person{public:Person(string name, int age){this->name = name;this->age = a...原创 2018-03-10 20:39:53 · 171 阅读 · 0 评论 -
23种设计模式之模板方法模式(行为型,1 Template Method,c++实现)
#include <iostream>using namespace std;class MakeCar{public:virtual void makeHead() = 0;virtual void makeBody() = 0;virtual void makeTail() = 0;public:void make(){makeTail();makeBody();makeHead(...原创 2018-03-11 12:17:40 · 153 阅读 · 0 评论 -
23种设计模式之命令模式(行为型,2 Command,c++实现)
代码实现:#include <iostream>#include <list>using namespace std;class Doctor{public:void treatEye(){cout << "treat eye" << endl;}void treatNose(){cout << "treat nose" &原创 2018-03-11 16:23:21 · 193 阅读 · 0 评论 -
23种设计模式之责任链模式(行为型,3 Chain of Responsibility,c++实现)
代码实现:#include <iostream>using namespace std;class CarHandler{public:virtual void handleCar() = 0;CarHandler* setNextHandler(CarHandler* handler){this->handler = handler;return handler;}protec...原创 2018-03-11 17:45:38 · 134 阅读 · 0 评论 -
23种设计模式之代理模式(结构型,1 Proxy,c++实现)
代码实现:#include <iostream>using namespace std;class Bookstore{public:virtual void sale() = 0;};class PhysicalBookstore :public Bookstore{public:void sale(){cout << "sale book" << endl;...原创 2018-03-04 16:55:56 · 197 阅读 · 0 评论 -
23种设计模式之迭代器模式(行为型,11 Iterator,c++实现)
代码实现:#include <iostream>using namespace std;typedef int Object;#define SIZE 5class Iterator {public:virtual void first() = 0;virtual void next() = 0;virtual bool hasNext() = 0;virtual Object get...原创 2018-03-25 12:58:10 · 239 阅读 · 0 评论