#include <iostream>
#include <string>

// -------------------- Subsystem Classes --------------------
class DVDPlayer {
public:
    void on() { std::cout << "DVD Player turned on" << std::endl; }
    void off() { std::cout << "DVD Player turned off" << std::endl; }
    void play(const std::string& movie) {
        std::cout << "Playing movie: " << movie << std::endl;
    }
    void stop() { std::cout << "Stopping playback" << std::endl; }
};

class Projector {
public:
    void on() { std::cout << "Projector turned on" << std::endl; }
    void off() { std::cout << "Projector turned off" << std::endl; }
    void setInput(const std::string& input) {
        std::cout << "Projector input switched to: " << input << std::endl;
    }
};

class SoundSystem {
public:
    void on() { std::cout << "Sound system turned on" << std::endl; }
    void off() { std::cout << "Sound system turned off" << std::endl; }
    void setVolume(int level) {
        std::cout << "Volume set to: " << level << std::endl;
    }
    void setMode(const std::string& mode) {
        std::cout << "Sound mode: " << mode << std::endl;
    }
};

class Lights {
public:
    void dim(int level) { std::cout << "Lights dimmed to: " << level << "%" << std::endl; }
    void on() { std::cout << "Lights turned on" << std::endl; }
};

// -------------------- Facade Class --------------------
class HomeTheaterFacade {
private:
    DVDPlayer dvd_;
    Projector projector_;
    SoundSystem sound_;
    Lights lights_;

public:
    HomeTheaterFacade() = default;

    void watchMovie(const std::string& movie) {
        std::cout << "===== Preparing to watch movie =====" << std::endl;
        lights_.dim(20);
        projector_.on();
        projector_.setInput("DVD");
        sound_.on();
        sound_.setMode("Cinema Mode");
        sound_.setVolume(8);
        dvd_.on();
        dvd_.play(movie);
        std::cout << "===== Enjoy the movie! =====\n" << std::endl;
    }

    void endMovie() {
        std::cout << "===== Ending movie =====" << std::endl;
        dvd_.stop();
        dvd_.off();
        sound_.off();
        projector_.off();
        lights_.on();
        std::cout << "===== System turned off =====\n" << std::endl;
    }
};

// -------------------- Client --------------------
int main() {
    // Use facade pattern to simplify operations
    HomeTheaterFacade homeTheater;

    // Watch a movie
    homeTheater.watchMovie("Interstellar");

    // End movie watching
    homeTheater.endMovie();

    return 0;
}

results matching ""

    No results matching ""