随笔分类 - 设计模式
摘要:#include <iostream> #include <vector> using namespace std; class Light { public: void on() { cout << "灯亮了" << endl; } void off() { cout << "灯灭了" << en
阅读全文
摘要:一、代码示例 1 #include <iostream> 2 #include <vector> 3 #include <string> 4 using namespace std; 5 6 ///抽象一个Subject主题 7 ///观察者 8 class Observer { 9 public:
阅读全文
摘要:1 #include <iostream> 2 using namespace std; 3 4 //设计思想:我们父类和子类就是一个扩展的关系?是不是合适 5 //里氏代换原则:子类对象就应该能完全替代父类的行为 6 //对于继承这样设计,特别小心,我们:组合大于继承 7 //把quack和fly
阅读全文
摘要:1 #include <iostream> 2 using namespace std; 3 4 //PC机,手机,平板 5 class MakeOrder { 6 public: 7 //virtual void startOrder() =0;第一版 8 //钩子函数的模板方法 9 virtua
阅读全文
摘要:一、代码示例 #include <iostream> using namespace std; // //class Computer { //public: // void run(); //}; // //class HpWindows7 :public Computer { // //}; /
阅读全文
摘要:#include <iostream> #include <list> #include <string> using namespace std; //component class IFile { public: virtual void displaye() = 0; virtual int
阅读全文
摘要:#include <iostream> #include <sstream> using namespace std; template <class T> string MyConvertToStr(T obj) { stringstream ss; ss << obj; return ss.st
阅读全文
摘要:/* AOP:叫面向方面(切面)编程 在我们的日常开发中,我们经常会遇到这样的一类与业务逻辑无关 的开发,正交化 打log,将log进入织入我们的业务场景 */ #include <memory> #include <string> #include <iostream> using namespa
阅读全文
摘要:一、截图 二、代码示例 #include <iostream> #include <string> #include <vector> using namespace std; //棋子的颜色 enum PieceColor { BLACK, WHTIE }; //棋子的位置 struct Piec
阅读全文
摘要:一、代码示例 #include <iostream> using namespace std; class Carmera { public: void turnOn() { cout << "相机启动" << endl; } void turnOff() { cout << "相机关闭" << e
阅读全文
摘要:#include <iostream> using namespace std; class ThreePhaseOutlet { public: void doThreePhasePlug() { cout << "三相插头接入" << endl; } }; class TwoPhaseOutle
阅读全文
摘要:1 #include <iostream> 2 #include <string> 3 #include <sstream> 4 #include <typeinfo> 5 using namespace std; 6 template <class T> 7 string iToStr(T val
阅读全文
摘要:1 #include <iostream> 2 #include <string> 3 #include <vector> 4 #include <sstream> 5 using namespace std; 6 7 template<class T> 8 string ConvertToStri
阅读全文
摘要:1 #include <iostream> 2 using namespace std; 3 4 class FrameApi { 5 public: 6 virtual void draw() = 0; 7 protected: 8 FrameApi() {}; 9 }; 10 11 class
阅读全文
摘要:#include <iostream> #include <string> using namespace std; class ExportFileApi { public: virtual bool exportData(string data) = 0; protected: ExportFi
阅读全文
摘要:一、线程安全性的讲解 1、视频截图 2、线程安全性的代码 加不加临界区进行验证 #include <afxwin.h> #include <iostream> #include <stdio.h> using namespace std; CRITICAL_SECTION g_cs; class S
阅读全文
摘要:一、第一种方法 //实现了客户端调用和implOne,implTwo的解耦合//factory类实现了变化隔离 1 #include<string> 2 #include "DynOBJ.h" 3 using namespace std; 4 5 class Api { 6 public: 7 vi
阅读全文