← Design Patterns learning path
Design Patterns · Module 5 of 10

Decorator and Proxy

Add behaviour dynamically and control access.

📖 Key ideas

  1. Decorator adds behaviour to objects without changing their class.
  2. Example: adding milk and sugar to a coffee object.
  3. Python decorators (@) wrap functions.
  4. Proxy controls access to another object: caching, lazy loading, permissions.
  5. Both wrap an object with the same interface.
💡 Real-life example: Decorator is adding toppings to a pizza; Proxy is a receptionist deciding who meets the boss.
DecoratorAdds behaviour by wrapping
ProxyStand-in controlling access
Python @decoratorFunction wrapping syntax
Lazy loadingLoading only when needed