๐Ÿงฉ Design Patterns with Java
Home Chapters Examples Diagrams Bibliography GitHub โ†—
  1. Home
  2. Creating Objects Under Control
Part 5 3 chapters

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.

Chapter 12

Factory Method and Abstract Factory

Two idiomatic Java 25 ways to keep object creation out of client code, taught against a regional shipping desk: an Abstract Factory that hands out a matching label formatter, rate table, and customs form per region, and a Factory Method that lets a shipment's category decide which inspection checklist runs inside a fixed sequence.

30 minRead โ†’
Chapter 13

Builder and Prototype

A Bloch-style Builder that assembles an international shipment and validates it only once, at build(), a record with wither methods for deriving a changed customs declaration, and a Prototype catalog that clones a named packaging exemplar into an independent copy, taught against a shipping domain.

30 minRead โ†’
Chapter 14

Singleton and the DI alternative

The two modern, correct ways to build a Java singleton, the enum form and the initialization-on-demand holder idiom, the older double-checked-locking approach they retire, and the dependency-injection alternative that gives the same reachable capability without the hidden global.

30 minRead โ†’
โ† Previous part Selecting and Varying Behavior Next part โ†’ Composing and Adapting Structure
Design Patterns with Java
Tutorial content: CC BY 4.0. Sample code: Apache 2.0.
Source on GitHub โ†—  ยท  File an issue โ†—