怎么样使用32行代码表示16个设计模式?
为了演示以下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<<"吃早饭";
}
本文地址:http://www.45fan.com/a/question/70658.html