StructuralC++verifiedVerified

Facade Pattern in C++

Provides a simplified, unified interface to a complex subsystem, hiding its internal complexity from clients.

How to Implement the Facade Pattern in C++

1Step 1: Complex subsystem classes

class VideoDecoder {
public:
    std::string decode(const std::string& file) {
        return "decoded:" + file;
    }
};

class AudioDecoder {
public:
    std::string decode(const std::string& file) {
        return "audio:" + file;
    }
};

class Renderer {
public:
    void render(const std::string& video, const std::string& audio) {
        std::cout << "Rendering " << video << " with " << audio << "\n";
    }
};

2Step 2: Facade simplifies the subsystem

class MediaPlayer {
    VideoDecoder video_;
    AudioDecoder audio_;
    Renderer renderer_;
public:
    void play(const std::string& file) {
        auto v = video_.decode(file);
        auto a = audio_.decode(file);
        renderer_.render(v, a);
    }
};

int main() {
    MediaPlayer player;
    player.play("movie.mp4");
}

Facade Pattern Architecture

hourglass_empty

Rendering diagram...

lightbulb

Facade Pattern in the Real World

A hotel concierge is a facade for the city’s complex infrastructure. Instead of you directly calling a taxi company, booking a restaurant, and arranging a museum ticket separately, the concierge handles all of it through a single conversation. The underlying services still exist in their full complexity—you just don’t deal with them directly.