๐Ÿงฉ Design Patterns with C++
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.

Chapter 12

Factory Method and Abstract Factory

Two idiomatic ways to keep object creation out of client code, taught against a carrier integration domain: an Abstract Factory that hands out a matching family of label formatter, rate quoter, and tracking client per carrier, and a Factory Method that lets an onboarding environment decide which integration test suite runs inside a fixed sequence.

30 minRead โ†’
Chapter 13

Builder, Prototype, and serialization

A fluent builder that assembles a multi-field shipment manifest and validates it only once, at build(), a small named registry of package prototypes that clone into fresh independent copies, and a plain-text serialization format that round-trips a manifest back to an equal value, taught against a freight dispatch domain.

30 minRead โ†’
Chapter 14

Singleton, and the dependency-injection alternative

The thread-safe Meyers singleton, the real costs it hides behind a convenient accessor, and the constructor-injected abstraction that gives the same capability without the global state, wired by a framework-free composition root.

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