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

public class VideoDecoder
{
    public string Decode(string filename) =>
        $"Decoded video: {filename}";
}

public class AudioDecoder
{
    public string Decode(string filename) =>
        $"Decoded audio: {filename}";
}

public class Renderer
{
    public string Render(string video, string audio) =>
        $"Rendered: {video} + {audio}";
}

2Step 2: Facade provides a simple interface

public class MediaPlayerFacade
{
    private readonly VideoDecoder _video = new();
    private readonly AudioDecoder _audio = new();
    private readonly Renderer _renderer = new();

    public string Play(string filename)
    {
        var video = _video.Decode(filename);
        var audio = _audio.Decode(filename);
        return _renderer.Render(video, audio);
    }
}

// Usage:
// var player = new MediaPlayerFacade();
// Console.WriteLine(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.