#include<stdio.h>
#include<iostream>
#include<string>
using namespace std;
/*外观模式:就是将复杂的子类系统抽象到同一个接口进行管理。外界只需要通过此接口与子类系统进行交互,
而不必直接与复杂的子类系统进行交互*/
//电视
class Television
{
public:
void on()
{
cout<<"电视打开"<<endl;
}
void off()
{
cout<<"电视机关闭"<<endl;
}
};
//音响
class Audio
{
public:
void on()
{
cout<<"音响打开"<<endl;
}
void off()
{
cout<<"音响关闭"<<endl;
}
};
//灯
class Light
{
public:
void on()
{
cout<<"灯打开"<<endl;
}
void off()
{
cout<<"灯关闭"<<endl;
}
};
//游戏机
class Game
{
public:
void on()
{
cout<<"游戏机打开"<<endl;
}
void off()
{
cout<<"游戏机关闭"<<endl;
}
};
class markphone
{
public:
void on()
{
cout<<"麦克风打开"<<endl;
}
void off()
{
cout<<"麦克风关闭"<<endl;
}
};
class Dvd
{
public:
void on()
{
cout<<"DVD打开"<<endl;
}
void off()
{
cout<<"DVD关闭"<<endl;
}
};
//实现ktv模式:电视打开,灯关掉,音响打开,麦克风打开,dvd打开
class KTVMode
{
public:KTVMode ()
{
ptv=new Television ;
plight=new Light ;
paudio=new Audio ;
pmark=new markphone ;
pdvd=new Dvd ;
}
void onKTV()
{
ptv ->on ();
plight ->off ();
paudio ->on ();
pmark ->on ();
pdvd ->on ();
}
void offKTV()
{
ptv ->off ();
plight ->on ();
paudio ->off ();
pmark ->off();
pdvd ->off();
}
~KTVMode ()
{
delete ptv ;
delete plight ;
delete paudio ;
delete pmark ;
delete pdvd ;
}
public:
Television *ptv;
Light *plight;
Audio *paudio;
markphone *pmark;
Dvd *pdvd;
};
//实现游戏模式:电视打开,音响打开,游戏机打开
//
void test01()
{
KTVMode *pktv=new KTVMode ;
pktv->onKTV();
}
int main()
{
test01();
}