Design Patterns
The 23 Gang of Four patterns, the SOLID principles behind them, and when each pattern helps or hurts.
Design patterns are named, reusable solutions to recurring object-oriented design problems. This section follows the classification in Design Patterns: Elements of Reusable Object-Oriented Software (Gamma, Helm, Johnson, Vlissides, 1994) — the “Gang of Four” (GoF). Each pattern is taught with a Java 21 example that CI compiles and runs.
Start with What Are Design Patterns? and SOLID Principles. Then read OO design principles behind the patterns and use the overview of all 23 patterns as your map. All 23 patterns are published; Compound patterns and MVC shows how they combine.
Topics in this section
Articles
- What Are Design Patterns?What a design pattern is (and is not), where the idea came from, how patterns relate to idioms and architecture, and how to use them without overengineering.
- SOLID PrinciplesThe five SOLID principles with Java examples: what each one actually says, the problem it prevents, how it connects to design patterns, and how to avoid applying it dogmatically.
- OO design principlesThe nine object-oriented design principles that the GoF patterns put into practice: encapsulate what varies, favour composition over inheritance, program to interfaces, loose coupling, open/closed, dependency inversion, least knowledge, the Hollywood Principle and single responsibility — each with the patterns that apply it.
- GoF OverviewA map of the 23 Gang of Four design patterns: the three categories, class versus object scope, one-line intents, JDK examples, and how to choose between patterns that look alike.
- Compound patterns and MVCPatterns rarely appear alone. How Model-View-Controller combines Observer, Strategy and Composite, how Spring MVC maps the idea to the web, MVC versus MVP and MVVM, and other common pattern combinations in real code.
Planned topics
These topics are on the roadmap and not written yet. They appear here so you can see the full scope of the section.
- Refactoring toward patterns: worked examples
- Anti-patterns and pattern overuse