Design Patterns for Changing Code
Design patterns give names to recurring software design problems and approaches. They are tools for assigning responsibilities, not finished code to copy unchanged.
- Who it is for: You can read functions and classes. The first lesson revisits objects and composition.
- Topics: Replacing behavior, notifying changes, creating objects, connecting interfaces, and separating state from presentation.
- Examples: Short Python 3 programs without external libraries. Every lesson is free to read.
- Goal: Explain what changes in a design and judge the benefits and costs of introducing a pattern.
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
- 01 Separate Roles and ContractsDistinguish inheritance from composition and supply dependencies from outside.
- 02 Strategy: Replace an AlgorithmSeparate a changing calculation and pass it to its caller.
- 03 Observer: Notify SubscribersConnect publishers and listeners through subscription.
- 04 Decorator: Wrap Additional BehaviorAdd behavior around an object while keeping its interface.
- 05 Factories: Separate Object CreationDistinguish Factory Method from Abstract Factory.
- 06 Singleton: Define the Scope of OneExamine shared object lifetime and the costs of global state.
- 07 Command: Represent a Request as an ObjectStore an action together with information needed to undo it.
- 08 Adapter and Facade: Connect and SimplifySeparate interface conversion from simplifying a workflow.
- 09 Template Method: Fix the Sequence, Vary a StepKeep a shared sequence while allowing selected steps to vary.
- 10 Iterator: Separate Traversal from StorageDistinguish a container from the state of a traversal.
- 11 Composite: Treat Items and Groups UniformlyGive leaves and groups a common operation in a tree.
- 12 State: Delegate Behavior by Current StateGroup allowed behavior and transitions by state.
- 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.