设计模式
.
「已注销」
这个作者很懒,什么都没留下…
展开
-
C++ 懒汉式单例
#include<iostream>//懒汉式单例 #include<pthread.h> #include<unistd.h> using namespace std; pthread_mutex_t mutex;//线程的同步机制问题 class singletion//单例类 { public: static singletion * getinstance()//提供给外部的创建对象的接口 { s.原创 2021-10-08 10:39:50 · 129 阅读 · 0 评论 -
C++ 工厂方法模式
#include<iostream> using namespace std; class car//抽象类 { public: virtual void construct() = 0; }; class BMW:public car { public: void construct() { cout<<"造一辆宝马汽车"<<endl; } }.原创 2021-10-08 10:32:21 · 45 阅读 · 0 评论 -
C++ 饿汉式单例
#include<iostream>//恶汉式单例 #include<pthread.h> #include<unistd.h> using namespace std; class singletion//单例类 { public: static singletion * getinstance()//提供给外部的创建对象的接口 { objcount++; .原创 2021-10-08 10:40:28 · 209 阅读 · 0 评论 -
C++ 简单工厂模式
#include<iostream> using namespace std; class car { public: void setengine(string engine){m_engine = engine;} void setwheel(string wheel){m_wheel = wheel;} void setbody(string body){m_body = body;} void display(.原创 2021-10-08 10:31:36 · 57 阅读 · 0 评论 -
C++ 外观模式
#include<iostream> using namespace std; class light { public: void on() { cout<<"开灯"<<endl; } void of() { cout<<"关灯"<<endl; } }; class TV { pub.原创 2021-10-08 10:41:21 · 145 阅读 · 0 评论 -
C++ 抽象工厂模式
#include<iostream> using namespace std; class car { public: void setengine(string engine){m_engine = engine;} void setwheel(string wheel){m_wheel = wheel;} void setbody(string body){m_body = body;} void display(.原创 2021-10-08 10:37:18 · 60 阅读 · 0 评论