๐Ÿงฉ Design patterns, taught in Java

Design patterns and SOLID principles, in modern Java.

The Gang of Four patterns and the SOLID principles, taught as decisions under forces rather than recipes to apply by reflex, with new, real-domain Java 25 code behind every chapter and a JUnit 5 and Mockito suite proving each example actually does what the chapter claims. Read it straight through, or jump to the part that answers the question you have right now.

Java 25 SOLID GoF patterns Maven JUnit 5 / Mockito

The parts

Thirteen parts, read in order the first time. Each part page lists its chapters; each chapter stands on its own for a reader jumping in to solve one problem. The orientation part is the map; start there if you only have time for one page.

Part 0

Orientation

The toolchain (JDK 25, Maven, JUnit 5, Mockito, AssertJ), how to read the book, and the codetabs convention that carries Classic Java and Java 25 side by side through every chapter.

1 chapterExplore โ†’
Part 1

Recognizing Design

Patterns as decisions under forces, not recipes to apply by reflex, and the shared vocabulary a team (and an AI pairing partner) needs to name what it sees.

2 chaptersExplore โ†’
Part 2

Principles (SOLID, Martin)

The five SOLID principles in modern Java terms: SRP/OCP/LSP first, then ISP/DIP and dependency injection without a framework.

2 chaptersExplore โ†’
Part 3

The Java Substrate

Records and sealed interfaces, immutability and defensive copying, and proving a design works with JUnit 5 before the patterns chapters begin.

3 chaptersExplore โ†’
Part 4

Selecting and Varying Behavior

Strategy, Template Method with hooks, State and finite-state machines (including probabilistic ones), and Command with undo and command queues.

4 chaptersExplore โ†’
Part 5

Creating Objects Under Control

Factory Method and Abstract Factory, Builder and Prototype (with serialization), and Singleton alongside the dependency-injection alternative and static factory methods.

3 chaptersExplore โ†’
Part 6

Composing and Adapting Structure

Adapter, Facade, and Bridge, Decorator and Proxy, and Composite and Flyweight alongside the Null Object idiom.

3 chaptersExplore โ†’
Part 7

Coordinating and Traversing

Observer and Mediator, Chain of Responsibility and Iterator with streams, and Visitor, Memento, and Interpreter.

3 chaptersExplore โ†’
Part 8

Idiomatic Java 25 Expressions

Records and sealed interfaces for pattern matching, functional interfaces and method references in place of classic callback hierarchies, and the Builder and static-factory idioms from Effective Java.

3 chaptersExplore โ†’
Part 9

Concurrency and Patterns in the Wild

Resource pools and virtual threads, shortcut patterns such as method-reference tables and dispatch maps, and anti-patterns to recognize and avoid.

5 chaptersExplore โ†’
Part 10

Changing Inherited Code (Modernized Feathers)

Seams and the test safety net, the dependency-breaking techniques updated for Java 25, Fowler contrasted and combined with Feathers, and when to refactor versus rewrite.

4 chaptersExplore โ†’
Part 11

Putting It Together

A final project that composes several patterns from the book, and a look at working with AI and LLM tools as a pattern-literate collaborator rather than a code vending machine.

2 chaptersExplore โ†’
Part 12

Appendices

A build and toolchain reference, a JUnit 5 reference, a Mockito mocking reference, an xUnit test-patterns guide, a pattern-to-force quick reference that maps every pattern, principle, and idiom in the book to the forces it answers, and a code-first review of the wider programming-principle vocabulary beyond SOLID.

6 chaptersExplore โ†’