SOLID & Design Patterns Interview Question #27

What is the Facade Pattern?

Structural, Creational & Behavioral Patterns Junior Beginner

Quick Interview Answer

The Facade Pattern provides a simplified interface over a more complex subsystem. Instead of requiring callers to coordinate several lower-level services, the facade exposes a smaller set of operations that represent common use cases.

Detailed Explanation

The Facade Pattern provides a simplified interface over a more complex subsystem. Instead of requiring callers to coordinate several lower-level services, the facade exposes a smaller set of operations that represent common use cases.

A facade does not necessarily hide every underlying component. Its purpose is to reduce complexity and coupling for typical clients while preserving the subsystem behind a clear boundary.

Code Example

public class CheckoutFacade
{
    private readonly IInventory _inventory;
    private readonly IPayment _payment;
    private readonly IShipping _shipping;

    public async Task PlaceOrderAsync(Order order)
    {
        await _inventory.ReserveAsync(order);
        await _payment.ChargeAsync(order);
        await _shipping.ScheduleAsync(order);
    }
}