为了演示以下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<<"吃早饭";
}