Mr. Latte


Design Patterns for Changing Code

Beginner / Python 3 / 13 lessons

Design patterns give names to recurring software design problems and approaches. They are tools for assigning responsibilities, not finished code to copy unchanged.

Do not multiply classes when a small function is enough. Look beyond output to the calls between objects and the parts expected to change.

Lessons

  1. 01 Separate Roles and ContractsDistinguish inheritance from composition and supply dependencies from outside.
  2. 02 Strategy: Replace an AlgorithmSeparate a changing calculation and pass it to its caller.
  3. 03 Observer: Notify SubscribersConnect publishers and listeners through subscription.
  4. 04 Decorator: Wrap Additional BehaviorAdd behavior around an object while keeping its interface.
  5. 05 Factories: Separate Object CreationDistinguish Factory Method from Abstract Factory.
  6. 06 Singleton: Define the Scope of OneExamine shared object lifetime and the costs of global state.
  7. 07 Command: Represent a Request as an ObjectStore an action together with information needed to undo it.
  8. 08 Adapter and Facade: Connect and SimplifySeparate interface conversion from simplifying a workflow.
  9. 09 Template Method: Fix the Sequence, Vary a StepKeep a shared sequence while allowing selected steps to vary.
  10. 10 Iterator: Separate Traversal from StorageDistinguish a container from the state of a traversal.
  11. 11 Composite: Treat Items and Groups UniformlyGive leaves and groups a common operation in a tree.
  12. 12 State: Delegate Behavior by Current StateGroup allowed behavior and transitions by state.
  13. 13 MVC and Choosing PatternsSeparate model, view, and controller, then choose only useful patterns.
Looking for a product partner? Founders, teams, businesses: from problem framing to launch.