🏗️Facade Pattern
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
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)Common mistake
Key takeaways
- 1One simple front. A few easy methods.
- 2The parts stay. Still usable directly.
- 3Hides, does not change. Same parts behind it.