liveBook · Manning

Facade pattern

As explained in Software Design for Python Programmers

The Façade pattern is a reusable design model that provides a simplified interface to a complex subsystem.

The Façade pattern gives a complex subsystem a simpler, higher-level interface. A façade hides the subsystem’s multiple interfaces so clients can perform a task through fewer calls. section 10.2 section 10.4

Fundraising through one operation

A university fundraising application coordinates alumni solicitations, booster-club meetings, and student-fee collection. Instead of having AthleticsDept and Administration call Alumni, BoosterClubs, and Students directly, both call FundRaiser.do_fund_raising(). FundRaiser contains the sequence of subsystem calls. section 10.2.3 section 10.2

A façade improves the surrounding design by:

  • Reducing duplication by placing fundraising operations in one façade method. section 10.2.3
  • Loosening coupling because clients depend on FundRaiser rather than each subsystem class. section 10.2.3
  • Containing change because adding another fundraising class affects the façade instead of every client. section 10.2.3
Listing 10.20 (Program 10.5 Funds-FaçadeDP) fund_raiser.py
from alumni import Alumni
from booster_clubs import BoosterClubs
from students import Students

class FundRaiser:
    def do_fund_raising(self):
        alumni = Alumni()
        clubs = BoosterClubs()
        students = Students()

        alumni.send_solicitations()
        clubs.schedule_meetings()
        students.collect_fees()

View the compact Python implementation of FundRaiser and its single do_fund_raising() operation. section 10.2.3

Choose a façade when the problem is a complex subsystem that needs a simpler entry point. Choose an Adapter when an existing class must be converted to a required target interface. section 10.3

How Software Design for Python Programmers covers it

How deep it goes
Explains the façade, demonstrates its Python structure, and contrasts it with Adapter without descending into implementation internals.
Examples
Uses a car-starting habit and university fundraising with FundRaiser, Alumni, BoosterClubs, Students, AthleticsDept, and Administration.
What it assumes
Assumes familiarity with classes and interfaces while teaching how clients, façades, and subsystem classes relate.
What you can do after
Build it from scratch by wrapping coordinated subsystem calls in a façade class and exposing a simpler client operation.
How it connects
Connects subsystem interfaces with Adapter, DRY, Principle of Least Knowledge, and Encapsulate What Varies.

Also explained in

Compare how 3 books explain facade pattern →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Software Design for Python Programmers. The section links point to the parts of the book it draws on.