#include<iostream>
using namespace std;
class Enter{
public:
void enter(){
cout<<"enter the bank"<<endl;
};
};
class Ticket{
public:
void getTicket(){
cout<<"get a ticket"<<endl;
};
};
class Save{
public:
void save(){
cout<<"now save the money"<<endl;
};
};
class Bomb{
public:
void bomb(){
cout<<"now bomb the bank"<<endl;
};
};
class Leave{
public:
void leave(){
cout<<"leave the bank"<<endl;
};
};
class Facade{
public:
Facade(){
enter = new Enter;
ticket = new Ticket;
save = new Save;
bomb = new Bomb;
leave = new Leave;
};
void bombBank(){
enter->enter();
ticket->getTicket();
bomb->bomb();
leave->leave();
};
void saveMoney(){
enter->enter();
ticket->getTicket();
save->save();
leave->leave();
};
private:
Enter * enter;
Ticket * ticket;
Save * save;
Bomb * bomb;
Leave * leave;
};
int main(){
Facade * f = new Facade;
f->saveMoney();
f->bombBank();
return 0;
}
外观模式c++实现
最新推荐文章于 2024-10-31 20:10:41 发布