标签:int ConcreteCommand1 模式 命令 初学 Invoker 设计模式
命令模式的代码例子
1 #include<iostream> 2 using namespace std; 3 class team1 4 { 5 public: 6 void DoSomeing() 7 { 8 cout<<"做一些事情"<<endl; 9 } 10 }; 11 12 class team2 13 { 14 public: 15 void DoSomeing() 16 { 17 cout<<"做一些事情"<<endl; 18 } 19 }; 20 21 class team3 22 { 23 public: 24 void DoSomeing() 25 { 26 cout<<"做一些事情"<<endl; 27 } 28 }; 29 30 class Command 31 { 32 protected: 33 team1 m_team1; 34 team2 m_team2; 35 team3 m_team3; 36 public: 37 virtual void exec() 38 {}; 39 40 }; 41 42 class ConcreteCommand1:public Command 43 { 44 public: 45 void exec() 46 { 47 m_team1.DoSomeing(); 48 }; 49 50 }; 51 class Invoker 52 { 53 private: 54 Command* m_CommandPtr; 55 public: 56 void AddCommand(Command *m_commandPtr) 57 { 58 m_CommandPtr=m_commandPtr; 59 }; 60 void Action() 61 { 62 m_CommandPtr->exec(); 63 }; 64 65 }; 66 67 68 int main() 69 { 70 ConcreteCommand1 m_ConcreteCommand1; 71 Invoker m_Invoker; 72 m_Invoker.AddCommand(&m_ConcreteCommand1); 73 m_Invoker.Action(); 74 getchar(); 75 return 0; 76 77 }
标签:int,ConcreteCommand1,模式,命令,初学,Invoker,设计模式 来源: https://www.cnblogs.com/wuhongjian/p/11823904.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。