Docs

Design Patterns — Fast Recall (Python)

Facade — one simple door to a complex system


  • What: a single class offering a high-level API that hides a messy multi-part subsystem.
  • Why / when: callers shouldn't need to know the order/details of many internal calls (e.g. `order.checkout()` hiding inventory + payment + shipping).
  • Benefit: decouples clients from internals — you can refactor behind the facade freely.
  • Remember: it simplifies, it doesn't restrict — the subsystem is still usable directly if needed.
1class CPU: def start(self): print("cpu on") 2class Disk: def load(self): print("os loaded") 3 4class Computer: # the facade 5 def __init__(self): 6 self.cpu, self.disk = CPU(), Disk() 7 def boot(self): # one call hides the steps 8 self.cpu.start(); self.disk.load() 9 10Computer().boot()