Unit 6 — Design Principles & Patterns¶
Learning objectives¶
- Explain cohesion, coupling, information hiding, and dependency direction.
- Apply SOLID principles as reasoning tools rather than slogans.
- Recognize when a design pattern clarifies a recurring design problem.
Localizing change¶
Good modular design aims to keep related responsibilities together and reduce unnecessary knowledge between modules. When a requirement changes, fewer components should need coordinated modification.
Design principles¶
- Single Responsibility: group things that change for the same reason.
- Open/Closed: enable common extensions without repeatedly editing stable code.
- Liskov Substitution: subtypes should preserve client expectations.
- Interface Segregation: avoid forcing clients to depend on operations they do not need.
- Dependency Inversion: high-level policy should not be tightly bound to volatile low-level detail.
Patterns¶
Patterns are named design knowledge, not code templates. Examples include Strategy, Observer, Adapter, Factory Method, and Dependency Injection.
Warning
Do not add patterns merely to make a design look sophisticated. Additional indirection has a cost.