文章分类 -  设计模式

摘要:单例模式分为饿汉式和懒汉式 饿汉式实现比较简单 //饿汉式class SingleTon1{ private static SingleTon1 instance=new SingleTon1(); private SingleTon1(){} public static SingleTon1 ge 阅读全文
posted @ 2024-03-25 18:50 dmfsimle 阅读(14) 评论(0) 推荐(0)
摘要:#include<iostream> #include<string> #include<list> using namespace std; //一般情况下 用继承实现类的功能拓展 装饰模式 可以动态给一个类增加功能 //抽象英雄 class AbstractHero { public: virt 阅读全文
posted @ 2024-03-25 17:59 dmfsimle 阅读(11) 评论(0) 推荐(0)
摘要:#include<iostream> using namespace std; class TV { public: void open() { cout << "打开电视" << endl; } void off() { cout << "关闭电视" << endl; } }; class Lig 阅读全文
posted @ 2024-03-25 17:58 dmfsimle 阅读(2) 评论(0) 推荐(0)
摘要:#include<iostream> #include<vector> #include<algorithm> using namespace std; struct MyPrint { void operator()(int v1,int v2){ cout << v1 + v2 << endl; 阅读全文
posted @ 2024-03-25 17:54 dmfsimle 阅读(7) 评论(0) 推荐(0)
摘要:#include<iostream> using namespace std; class DrinkTemplate { public: virtual void BoilWater() = 0;//煮开水 virtual void Brew() = 0;//冲泡 virtual void Pou 阅读全文
posted @ 2024-03-25 17:54 dmfsimle 阅读(6) 评论(0) 推荐(0)
摘要:#include<iostream> #include<queue> using namespace std; class HandleClientProtocol { public: //处理金币 void AddMoney() { cout << "增加金币" << endl; } //增加砖石 阅读全文
posted @ 2024-03-25 17:53 dmfsimle 阅读(6) 评论(0) 推荐(0)
摘要:#include<iostream> #include<string> using namespace std; class AbstractFruit { public: virtual void showname() = 0; }; class Apple :public AbstractFru 阅读全文
posted @ 2024-03-25 17:52 dmfsimle 阅读(5) 评论(0) 推荐(0)
摘要:#include<iostream> #include<string> #include<list> using namespace std; class AbstractHero { public: virtual void Update() = 0; }; class HeroA :public 阅读全文
posted @ 2024-03-25 17:51 dmfsimle 阅读(6) 评论(0) 推荐(0)
摘要:#include<iostream> #include<vector> #include<algorithm> using namespace std; //水果基类 class AstractFruit { public: virtual void showname() = 0; }; class 阅读全文
posted @ 2024-03-25 17:51 dmfsimle 阅读(15) 评论(0) 推荐(0)
摘要:#include<iostream> using namespace std; //单例 class SingleTon { public: static SingleTon* getinstance() { if (instance == nullptr)instance = new Single 阅读全文
posted @ 2024-03-25 17:49 dmfsimle 阅读(5) 评论(0) 推荐(0)
摘要:#include<iostream> #include<string> using namespace std; class AbstractCommonInterface { public: virtual void run() = 0; }; class MySystem :public Abs 阅读全文
posted @ 2024-03-25 17:49 dmfsimle 阅读(8) 评论(0) 推荐(0)
摘要:#include<iostream> using namespace std; //武器策略 class WeaponStrategy { public: virtual void UseWeapon() = 0; }; //匕首策略 class KnifeStrategy :public Weap 阅读全文
posted @ 2024-03-25 17:48 dmfsimle 阅读(7) 评论(0) 推荐(0)
摘要:#include<iostream> using namespace std; //苹果抽象类 class AbstractApple { public: virtual void ShowName() = 0; }; //中国苹果 class ChinaApple :public Abstract 阅读全文
posted @ 2024-03-25 17:47 dmfsimle 阅读(10) 评论(0) 推荐(0)