用32行程式碼表示16個設計模式 (轉)
為了演示以下16個,用了下面32行程式碼。
iterator,adapter,interpreter,,
state,visitor,command,bridge,
chain of responsibility,composite,
flyweight,strategy,decorator,
mediator,memento,observer
void main(){
for(i=0;i<2;i++){
if (i==0){Actor getUpActor=new GetUpActor();
getUpActor.Action();
delete getUpActor;}
else if(i==1){Actor supperActor=new SupperActor();
supperActor.Action();
delete supperActor;
}
}
class Actor(){
public:
virtual void Action()=0;
protected:
Actor();
};
class GetUpActor():public Actor{
public:
virtual void Action();
GetUpActor();
};
void GetUpActor:Action{
cout<}
class SupperActor():public Actor{
public:
virtual void Action();
SupperActor();
};
void SupperActor():Action{
cout<}
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10748419/viewspace-1008735/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 設計模式怎麼用UML圖表示?設計模式
- 如何在程式碼中應用設計模式設計模式
- 用OC程式碼認識設計模式(一) 建立型模式C程式設計模式
- 用OC程式碼認識設計模式(三) 行為型模式C程式設計模式
- Java設計模式(16)----------命令模式Java設計模式
- 設計複合應用程式:設計模式設計模式
- 設計模式、用Delphi描述-->Visitor模式 (轉)設計模式
- 設計模式、用Delphi描述-->Factory Method模式 (轉)設計模式
- 設計模式、用Delphi描述-->Abstract Factory模式 (轉)設計模式
- 設計模式、用Delphi實現---->Builder模式 (轉)設計模式UI
- 設計模式例項程式碼設計模式
- Python程式設計:探索有趣的程式碼設計模式Python程式設計設計模式
- 【程式碼簡述設計模式】----- 觀察者模式設計模式
- 設計模式、用Delphi實現---->Singleton 模式 (轉)設計模式
- 設計模式之高質量程式碼設計模式
- 走近設計模式:寫程式碼一定要用設計模式嗎?設計模式
- 設計模式、用Delphi描述-->Lock pattern (轉)設計模式
- Linux系統程式設計(16)——正規表示式入門Linux程式設計
- C#設計模式(16)——中介者模式C#設計模式
- 設計模式 - java程式碼實現單例模式設計模式Java單例
- 設計模式-策略模式(轉)設計模式
- 設計模式及其在spring中的應用(含程式碼)設計模式Spring
- 玩轉設計模式——設計模式之禪設計模式
- 16種JavaScript設計模式(中)JavaScript設計模式
- 16種JavaScript設計模式(上)JavaScript設計模式
- 設計模式、用Delphi描述-->Reference Count pattern (轉)設計模式
- FPGA設計--數字的表示形式(程式碼+波形圖)FPGA
- 16.java設計模式之迭代器模式Java設計模式
- 程式設計師程式設計的10個實用技巧程式設計師
- .NET應用架構設計—表模組模式與事務指令碼模式的程式碼編寫應用架構模式指令碼
- 設計模式—單例模式(轉)設計模式單例
- 你說寫程式碼,最常用的3個設計模式是啥?設計模式
- 從碼農到設計者,從單例模式入手設計程式碼單例模式
- Python+django網頁設計入門(16):優化設計複用分頁程式碼PythonDjango網頁優化
- 【Perl程式設計-6】正規表示式--替換+轉化程式設計
- 我這個程式設計師 (轉)程式設計師
- ADO程式設計應用 (轉)程式設計
- Python程式設計的16個壞習慣Python程式設計