Diagrams for the book, trending toward a C4-style standard.
Click any diagram to open it fullscreen. Each is
also available as .excalidraw source; open it on
excalidraw.com
to edit.
Ch. 0
The local build-and-test loop
The edit, mvn test, observe loop every example runs: a source change is compiled against JDK 25 and exercised by the JUnit 5 suite with Mockito and AssertJ, and a failing assertion sends you back to the source. A standalone module and the root aggregator run the identical loop.
The arc the book trains for every pattern: recognize the forces, name a candidate pattern and a candidate non-pattern, choose the idiomatic Java expression, test the behavior, and know when not to use it.
A pattern name sits between three readers, an engineer, a teammate, and an AI assistant, each one meant to read the same forces off the same word, not just the word itself.
InvoiceCalculator depends on the InvoiceRule abstraction, never on a concrete rule, so a new rule arrives as a new type that implements the contract with no edit to the calculator or the rules that predate it.
A high-level policy depends on a role interface, not a concrete gateway, and the concrete gateways implement that same abstraction, so both sides meet at the interface instead of the policy reaching for a detail.
A try-with-resources scope runs close() on both the normal exit and an exception unwinding the block, so a resource is released exactly once no matter how control leaves the scope.
A caller depends only on the public interface and a static factory; the concrete implementation and the representation behind it stay package-private, free to change without touching the caller.
One JUnit 5 test arranged with a mock, acting on the subject, and asserted two ways: AssertJ on the returned value and Mockito.verify on the interaction with a collaborator.
One caller, one contract, and a set of interchangeable algorithms behind it, each expressed a different idiomatic way, swapped without touching the caller.
The order-processing pipeline's fixed, final sequence runs an invariant check and three varying steps in order; a channel supplies those steps by overriding an abstract class or by handing the pipeline three lambdas.
The legal shipment states and the transitions between them, with the stochastic outlet the probabilistic machine draws from while a shipment is in transit.
A request becomes a command that flows through a queue and an undo-redo history into the warehouse ledger, so it can be ordered, replayed, and reversed rather than run and forgotten.
A regional factory resolves one toolkit from a region value, and the chosen toolkit's whole family of label formatter, rate table, and customs form reaches the client together, from a single factory call.
A builder accumulates required and optional fields and validates every invariant once at build time; a prototype clones a configured exemplar into an independent copy rather than rebuilding it.
A global singleton's callers reach one shared instance with no parameter announcing it; the injected alternative routes the same capability through a constructor a composition root controls, which is what makes it testable.
Adapter wraps a foreign type to the interface the app expects, Facade presents one small surface over a subsystem, and Bridge lets an abstraction and its implementation vary without a class for every combination.
A decorator stack adds behavior layer by layer behind the same interface, while a proxy stands in front of the real subject through that same interface to control access, caching, or lazy creation.
Composite lets a leaf and a tree answer the same interface so a caller treats them alike; Flyweight interns one shared instance of immutable intrinsic state that many objects point at instead of each holding a copy.
An Observer subject fans a change out to independent listeners that it never names, next to a Mediator hub that routes between collaborators so they never call each other directly.
Pass along handlers; traverse without exposing structure
A request passes down a chain of handlers until one takes it and the rest never run, while an iterator walks an aggregate's elements in order without the caller knowing how they are stored.
A fixed set of node kinds on one side, several independent operations on the other, each operation its own exhaustive pattern-matching switch with no accept method anywhere on the node types.
A sealed set of record variants on one side and several external operations on the other, each an exhaustive pattern-matching switch the compiler checks, with no accept method anywhere on the record types.
A shipment moves through enum-carried behavior, a functional Strategy or Command, a stream pipeline, and an Optional return, each stage an idiomatic Java 25 construct that is also a classic pattern in disguise.
Each classic idiom built by hand, paired with the Java 25 feature that gets the identical guarantee from the compiler or the runtime instead: the enum for the singleton, the record for the value class, sealed plus switch for the visitor, Optional for the null check.
Many virtual threads mount and unmount on a small pool of carrier threads while they block on I/O, so thousands of blocking carrier calls run concurrently without thousands of platform threads.
A bounded connection pool hands out leases up to its capacity and blocks further callers until one is returned, with a timeout path for a caller that waits too long.
A closed enum key and an open string key each resolve through a small dispatch table to a short handler, and an unmatched open key still has a defined fallback route.
A design stacked with a singleton registry, a one-implementation interface, a factory of factories, and a god object collapses to the simpler service that does the same job and passes the same tests.
The Quarkus Arc container wires the beans, and each CDI mechanism answers a pattern the book built by hand: @ConfigMapping for Strategy selection, @Produces for Factory, @ApplicationScoped plus constructor injection for Singleton and DI, an @AroundInvoke interceptor for Decorator and Proxy, and a CDI event with @Observes for Observer.
The same inherited dependencies made substitutable: an object seam injects a Clock, an extract-interface seam puts a CarrierGateway behind an interface a test can replace, and subclass-and-override opens a seam where there is no constructor to change.
A class that constructs and calls a concrete collaborator directly, with no seam, becomes testable once Extract Interface and Parameterize Constructor let either the real gateway or a test double sit behind the interface.
A characterization suite pins the legacy calculator's current behavior, so a Fowler-style refactor to a cleaner calculator is verified safe when every pinned case stays green.
A router behind a stable interface consults a migration registry and sends each shipment to the legacy or the modern calculator, so the new implementation grows while the old still serves un-migrated traffic.
The dispatch center as composition root: a builder resolves the rate strategy per carrier, commands act on the shared shipment, and the shipment notifies its status listeners, each pattern earning its place by the force it answers.
One shipment's run in time order through the composed patterns: open a quote, pick up, dispatch, correct the weight, undo the correction, and deliver, with illegal transitions refused.
The engineer names the forces and the candidate pattern, an assistant drafts an implementation, and a gate of behavior tests and an idiomatic review accepts the draft or sends it back, keeping responsibility for correctness with the engineer.
The same shipment transition stated two ways: an EnumMap transition table and a sealed-interface exhaustive switch, where a missing case is a compile error rather than a silent miss.
The principle vocabulary grouped into six families, from a tight SOLID recap through simplicity, structure, coupling, and interoperability to a process family with no code shape at all.