/*
外观模式就是讲负责的子类系统抽象到同一个的接口进行管理,外界只需要通过此接口与子类系统进行交互,而不必要直接与复杂的子类系统进行交互。
*/
# include <iostream>
using namespace std;
//电视机类
class Tevevision
{
public:
void On()
{
cout << "电视机打开..." << endl;
}
void Off()
{
cout << "电视机关闭..." << endl;
}
};
//灯类
class Light
{
public:
void On()
{
cout << "灯打开..." << endl;
}
void Off()
{
cout << "灯关闭..." << endl;
}
};
//音响类
class Audio
{
public:
void On()
{
cout << "音响打开..." << endl;
}
void Off()
{
cout << "音响关闭..." << endl;
}
};
//麦克风类
class Mircophone
{
public:
void On()
{
cout << "麦克风打开..." << endl;
}
void Off()
{
cout << "麦克风关闭..." << endl;
}
};
//DVD播放器类
class DVDPlayer
{
public:
void On()
{
cout << "DVD打开..." << endl;
}
void Off()
{
cout << "DVD关闭..." << endl;
}
};
//游戏机类
class GamePlayer
{
public:
void On()
{
cout << "游戏机打开..." << endl;
}
void Off()
{
cout << "游戏机关闭..." << endl;
}
};
class KTVMode
{
public:
KTVMode()
{
ptv = new Tevevision;
pLight = new Light;
pAudio = new Audio;
pMircophone = new Mircophone;
pDVDPlayer = new DVDPlayer;
}
void OnKtv()
{
this->ptv->On();
this->pLight->Off();
this->pAudio->On();
this->pMircophone->On();
this->pDVDPlayer->On();
}
void OffKtv()
{
this->ptv->Off();
this->pLight->On();
this->pAudio->Off();
this->pMircophone->Off();
this->pDVDPlayer->Off();
}
~KTVMode()
{
delete ptv;
delete pLight;
delete pAudio;
delete pMircophone;
delete pDVDPlayer;
}
public:
Tevevision *ptv;
Light *pLight;
Audio *pAudio;
Mircophone *pMircophone;
DVDPlayer *pDVDPlayer;
};
void test01()
{
KTVMode* ktv = new KTVMode;
ktv->OnKtv();
}
int main(int argc, char *argv[])
{
test01();
return 0;
}
外观模式就是讲负责的子类系统抽象到同一个的接口进行管理,外界只需要通过此接口与子类系统进行交互,而不必要直接与复杂的子类系统进行交互。
*/
# include <iostream>
using namespace std;
//电视机类
class Tevevision
{
public:
void On()
{
cout << "电视机打开..." << endl;
}
void Off()
{
cout << "电视机关闭..." << endl;
}
};
//灯类
class Light
{
public:
void On()
{
cout << "灯打开..." << endl;
}
void Off()
{
cout << "灯关闭..." << endl;
}
};
//音响类
class Audio
{
public:
void On()
{
cout << "音响打开..." << endl;
}
void Off()
{
cout << "音响关闭..." << endl;
}
};
//麦克风类
class Mircophone
{
public:
void On()
{
cout << "麦克风打开..." << endl;
}
void Off()
{
cout << "麦克风关闭..." << endl;
}
};
//DVD播放器类
class DVDPlayer
{
public:
void On()
{
cout << "DVD打开..." << endl;
}
void Off()
{
cout << "DVD关闭..." << endl;
}
};
//游戏机类
class GamePlayer
{
public:
void On()
{
cout << "游戏机打开..." << endl;
}
void Off()
{
cout << "游戏机关闭..." << endl;
}
};
class KTVMode
{
public:
KTVMode()
{
ptv = new Tevevision;
pLight = new Light;
pAudio = new Audio;
pMircophone = new Mircophone;
pDVDPlayer = new DVDPlayer;
}
void OnKtv()
{
this->ptv->On();
this->pLight->Off();
this->pAudio->On();
this->pMircophone->On();
this->pDVDPlayer->On();
}
void OffKtv()
{
this->ptv->Off();
this->pLight->On();
this->pAudio->Off();
this->pMircophone->Off();
this->pDVDPlayer->Off();
}
~KTVMode()
{
delete ptv;
delete pLight;
delete pAudio;
delete pMircophone;
delete pDVDPlayer;
}
public:
Tevevision *ptv;
Light *pLight;
Audio *pAudio;
Mircophone *pMircophone;
DVDPlayer *pDVDPlayer;
};
void test01()
{
KTVMode* ktv = new KTVMode;
ktv->OnKtv();
}
int main(int argc, char *argv[])
{
test01();
return 0;
}