๐Ÿงฉ Design Patterns with Java
Home Chapters Examples Diagrams Bibliography GitHub โ†—
  1. Home
  2. The Java Substrate
Part 3 3 chapters

The Java Substrate

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

Chapter 5

Resource management (Java's RAII)

Deterministic cleanup without a destructor: try-with-resources and AutoCloseable as Java's primary answer, and the Execute-Around Method idiom for the cases a resource's open/use/close sequence belongs to a library rather than every call site, taught against a carrier connection, a batch ledger writer, and a pooled tracking-feed handle.

30 minRead โ†’
Chapter 6

Encapsulation and API design

A shipping-tracking gateway built behind a public interface with a package-private implementation reached through a static factory, and a Shipment/Manifest/TrackingHistory value model built from records whose compact constructors defend every collection field with List.copyOf.

30 minRead โ†’
Chapter 7

Testing with JUnit 5, Mockito, and AssertJ

The testing stack every example in this book runs behind the scenes: JUnit 5's lifecycle and parameterized tests, Mockito's mocks and spies, and AssertJ's fluent assertions, taught against a shipment-booking service with one collaborator mocked and two called directly.

35 minRead โ†’
โ† Previous part Principles (SOLID, Martin) Next part โ†’ Selecting and Varying Behavior
Design Patterns with Java
Tutorial content: CC BY 4.0. Sample code: Apache 2.0.
Source on GitHub โ†—  ยท  File an issue โ†—