模板模式
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include <iostream> 2 using namespace std; 3 4 //PC机,手机,平板 5 class MakeOrder { 6 public: 7 //virtual void startOrder() =0;第一版 8 //钩子函数的模板方法 9 virtual void startOrder() { 10 cout << "下订单了" << endl; 11 } 12 virtual void replyStart()=0; 13 //..... 14 virtual void finishOrder()=0; 15 virtual void replyFinish()=0; 16 //模板模式 17 void make() { 18 startOrder(); 19 replyStart(); 20 finishOrder(); 21 replyFinish(); 22 } 23 protected: 24 MakeOrder(){} 25 }; 26 27 class Fanuc :public MakeOrder { 28 public: 29 void startOrder() { 30 cout << "Fanuc开始接受订单" << endl; 31 } 32 void replyStart() { 33 cout << "Fanuc做好预备,请将后继订单进入排队" << endl; 34 } 35 //..... 36 void finishOrder() { 37 cout << "本次Fanuc订单已经完成,请推进下个订单进入生产" << endl; 38 } 39 void replyFinish() { 40 cout << "Fanuc订单信号已经送达,即将推进下个订单进入生产" << endl; 41 } 42 }; 43 44 class Sims :public MakeOrder { 45 public: 46 void startOrder() { 47 cout << "Sims开始接受订单" << endl; 48 } 49 void replyStart() { 50 cout << "Sims做好预备,请将后继订单进入排队" << endl; 51 } 52 //..... 53 void finishOrder() { 54 cout << "本次Sims订单已经完成,请推进下个订单进入生产" << endl; 55 } 56 void replyFinish() { 57 cout << "Sims订单信号已经送达,即将推进下个订单进入生产" << endl; 58 } 59 }; 60 61 class Mits :public MakeOrder { 62 public: 63 64 void replyStart() { 65 cout << "Sims做好预备,请将后继订单进入排队" << endl; 66 } 67 //..... 68 void finishOrder() { 69 cout << "本次Sims订单已经完成,请推进下个订单进入生产" << endl; 70 } 71 void replyFinish() { 72 cout << "Sims订单信号已经送达,即将推进下个订单进入生产" << endl; 73 } 74 }; 75 76 int main(void) { 77 //MakeOrder* pMakeOrder = new Fanuc; 78 //pMakeOrder->make(); 79 MakeOrder* pMakeOrder = new Mits; 80 pMakeOrder->make(); 81 system("pause"); 82 return 0;