Класс HomeTheaterFacade - Usergaser/Facade GitHub Wiki
HomeTheaterFacade
Главный файл Паттерна Фасад. Содержит следующие методы:
- WatchMovie()
- endMovie()
- listenToCd()
- endCd()
- listenToRadio()
- endRadio()
Также к HomeTheaterFacade привязаны файлы:
- Apmlifier
- Tuner
- DvdPlayer
- CdPlayer
- Screen
- PopcornPopper
- TheaterLights
- Projector
Илюстрация связей файла HomeTheatreFacade:
Код файла HomeTheatreFacade.h:
`
#ifndef HOMETHEATERFACADE_H
#define HOMETHEATERFACADE_H
#include QString
#include iostream
#include "amplifier.h"
#include "tuner.h"
#include "dvdplayer.h"
#include "cdplayer.h"
#include "projector.h"
#include "screen.h"
#include "popcornpopper.h"
#include "theaterlights.h"
using namespace std;
class HomeTheaterFacade
{
private:
Amplifier *amp; Tuner *tuner; DvdPlayer *dvd; CdPlayer *cd; Projector *projector; TheaterLights *lights; Screen *screen; PopcornPopper *popper;
public:
HomeTheaterFacade(Amplifier*,Tuner*,DvdPlayer*,CdPlayer*,Projector*,TheaterLights*,Screen*,PopcornPopper*); void watchMovie(QString movie); void endMovie(); void listenToCd(QString cdTitle); void endCd(); void listenToRadio(double frequency); void endRadio();
};
#endif // HOMETHEATERFACADE_H `
Код файла HomeTheatreFacade.cpp:
`
#include "hometheaterfacade.h"
HomeTheaterFacade::HomeTheaterFacade (Amplifier *amp,Tuner *tuner,DvdPlayer *dvd,CdPlayer *cd,Projector *projector,TheaterLights *lights,Screen *screen,PopcornPopper *popper) {
this->amp = amp; this->tuner = tuner; this->dvd = dvd; this->cd = cd; this->projector = projector; this->screen = screen; this->lights = lights; this->popper = popper;
}
void HomeTheaterFacade::watchMovie(QString movie) {
cout << "Get ready to watch a movie..." << endl; popper->on(); popper->pop(); lights->dim(10); screen->down(); projector->on(); projector->wideScreenMode(); amp->on(); amp->setDvd(dvd); amp->setSurroundSound(); amp->setVolume(5); dvd->on(); dvd->play(movie);
}
void HomeTheaterFacade::endMovie() {
cout << "Shutting movie theater down..." << endl; popper->off(); lights->on(); screen->up(); projector->off(); amp->off(); dvd->stop(); dvd->eject(); dvd->off();
}
void HomeTheaterFacade::listenToCd(QString cdTitle) {
cout << "Get ready for an audiopile experence..." << endl; lights->on(); amp->on(); amp->setVolume(5); amp->setCd(cd); amp->setStereoSound(); cd->on(); cd->play(cdTitle);
}
void HomeTheaterFacade::endCd() {
cout << "Shutting down cd->.." << endl; amp->off(); amp->setCd(cd); cd->eject(); cd->off();
}
void HomeTheaterFacade::listenToRadio(double frequency) {
cout << "Tuning in the airwaves..." << endl; tuner->on(); tuner->setFrequency(frequency); amp->on(); amp->setVolume(5); amp->setTuner(tuner);
}
void HomeTheaterFacade::endRadio() {
cout << "Shutting down the tuner->.." << endl; tuner->off(); amp->off();
}
`
(О описании метода Фасад можно прочитать Здесь)