Goal: use patterns to clarify design, not to decorate simple code.
Use for:
- recurring design problems with known solutions
- naming and structuring a chosen approach
- reviewing whether a pattern fits or adds noise
Workflow:
- State the actual problem and forces involved.
- Match it to a pattern's intent, not its name.
- Apply the smallest form that solves the problem.
- Name the participants clearly in the code.
- Reassess: would plain code be simpler here.
- Verify behavior is unchanged and clearer.
Common patterns:
- strategy for interchangeable behavior
- factory for controlled construction
- adapter to bridge incompatible interfaces
- observer for event notification
- decorator to add behavior without subclassing
Rules:
- choose by intent, not by familiarity
- do not introduce a pattern for a one-off case
- prefer composition over inheritance-heavy patterns
- the simplest design that works beats a clever one