CSDN博客

img xxcc

用32行代码表示16个设计模式

发表于2002/6/22 17:38:00  1518人阅读

分类: 模式

为了演示以下16个模式,用了下面32行代码。
iterator,adapter,interpreter,proxy,
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<<"吃早饭";
}

0 0

相关博文

我的热门文章

img
取 消
img