Skip to content
BENIBIX Learn

Facade Pattern

Development🏗️ ArchitectureDesign Patterns

Also known as Facade Design Pattern, Façade Pattern, Facade

One simple front for many parts. Callers need just one call.

Think of it like

It is like a TV remote. One button turns on the TV, the speaker and the box together.

Example

Emma's shop has an order facade with one method, place(). Behind it, place() checks stock, takes payment and books the delivery.

Why it matters

Most code needs only the common path. A facade keeps that code short and keeps the messy parts in one place.

Definition

The facade pattern puts one simple interface in front of a group of complex parts. Callers use a few easy methods on the facade. The facade then calls the many classes behind it in the right order. The parts behind it still exist and can be used directly if needed. It hides detail, but it does not change what the parts do.

Example code

python
class OrderFacade:
    def place(self, cart, card):
        self.stock.reserve(cart)
        self.payments.charge(card, cart.total)
        return self.shipping.book(cart)
One call to place() runs three parts in the right order.
Facade, bottom left: one place order call in front of stock, payment and shipping.

Common mistake

Letting the facade grow until it does everything. Then it becomes one huge class that is hard to change.

Key takeaways

  1. 1
    One simple front. A few easy methods.
  2. 2
    The parts stay. Still usable directly.
  3. 3
    Hides, does not change. Same parts behind it.

Compare