Design Principles & Patterns
The heuristics that keep a design honest as it grows — DRY, KISS, YAGNI, composition over inheritance, coupling and cohesion — the discipline of noticing and fixing a design that's gone bad (code smells, refactoring, test-driven development), and the Gang-of-Four catalog of creational, structural, and behavioral design patterns as the recurring shapes those heuristics produce in practice. Fifteen lessons that assume object-oriented programming and SOLID as a starting point (see software-architect) and go one layer deeper than computer-science's single GoF survey lesson into the patterns themselves.
DRY, KISS, and YAGNIThree heuristics against duplicated logic, needless complexity, and speculative work — what each one actually guards against, and where each gets misapplied.Separation of Concerns, Coupling, and CohesionWhat a "concern" is, why mixing two of them in one module causes pain later, and coupling and cohesion as the measurable form of the same idea.Composition Over InheritanceWhy deep inheritance hierarchies get brittle as requirements shift, and the "has-a instead of is-a" fix, worked through the classic Duck example.Code Smells and RefactoringWhat a code smell actually is — a symptom, not a bug — the classic named smells, and refactoring as disciplined, test-covered structural repair.Test-Driven DevelopmentThe red-green-refactor cycle, and how writing the test before the code changes the shape of the design you end up with.Singleton and Factory MethodOne guaranteed instance versus one hidden decision about which concrete class to build — and why Singleton's convenience comes with a real cost.Abstract Factory and BuilderA factory that produces matching families of related objects, and building one complex object step by step instead of an 8-argument constructor.The Prototype PatternCloning an already-configured object instead of building one from scratch — and the shallow-versus-deep-copy trap that makes cloning riskier than it looks.Adapter and FacadeAdapter translates a mismatched interface so existing code keeps working; Facade hides a tangled subsystem behind one simple entry point.Decorator and ProxyDecorator and Proxy both wrap an object behind its own interface — Decorator adds behavior at runtime, Proxy controls access to the real thing.Composite, Bridge, and FlyweightComposite unifies a tree under one interface, Bridge splits two axes of variation apart, and Flyweight shares identical state across millions of objects.Observer and StrategyObserver lets objects subscribe to state changes without knowing each other's types; Strategy swaps an algorithm's implementation behind one shared interface.Command and StateCommand turns a request into an object with its own execute and undo; State replaces a sprawling conditional with one class per mode of behavior.Template Method and Chain of ResponsibilityTemplate Method fixes an algorithm's skeleton with overridable steps; Chain of Responsibility passes a request along handlers until one handles it.Iterator, Mediator, Memento, and VisitorFour more behavioral patterns: collection traversal, centralized object communication, state snapshots for undo, and adding operations without touching classes.
Design principles
- DRY, KISS, and YAGNIThree heuristics against duplicated logic, needless complexity, and speculative work — what each one actually guards against, and where each gets misapplied.
- Separation of Concerns, Coupling, and CohesionWhat a "concern" is, why mixing two of them in one module causes pain later, and coupling and cohesion as the measurable form of the same idea.
- Composition Over InheritanceWhy deep inheritance hierarchies get brittle as requirements shift, and the "has-a instead of is-a" fix, worked through the classic Duck example.
Code quality in practice
- Code Smells and RefactoringWhat a code smell actually is — a symptom, not a bug — the classic named smells, and refactoring as disciplined, test-covered structural repair.
- Test-Driven DevelopmentThe red-green-refactor cycle, and how writing the test before the code changes the shape of the design you end up with.
Creational patterns
- Singleton and Factory MethodOne guaranteed instance versus one hidden decision about which concrete class to build — and why Singleton's convenience comes with a real cost.
- Abstract Factory and BuilderA factory that produces matching families of related objects, and building one complex object step by step instead of an 8-argument constructor.
- The Prototype PatternCloning an already-configured object instead of building one from scratch — and the shallow-versus-deep-copy trap that makes cloning riskier than it looks.
Structural patterns
- Adapter and FacadeAdapter translates a mismatched interface so existing code keeps working; Facade hides a tangled subsystem behind one simple entry point.
- Decorator and ProxyDecorator and Proxy both wrap an object behind its own interface — Decorator adds behavior at runtime, Proxy controls access to the real thing.
- Composite, Bridge, and FlyweightComposite unifies a tree under one interface, Bridge splits two axes of variation apart, and Flyweight shares identical state across millions of objects.
Behavioral patterns
- Observer and StrategyObserver lets objects subscribe to state changes without knowing each other's types; Strategy swaps an algorithm's implementation behind one shared interface.
- Command and StateCommand turns a request into an object with its own execute and undo; State replaces a sprawling conditional with one class per mode of behavior.
- Template Method and Chain of ResponsibilityTemplate Method fixes an algorithm's skeleton with overridable steps; Chain of Responsibility passes a request along handlers until one handles it.
- Iterator, Mediator, Memento, and VisitorFour more behavioral patterns: collection traversal, centralized object communication, state snapshots for undo, and adding operations without touching classes.