liveBook · Manning

Design pattern

As explained in The Art of Code

A design pattern is a named, reusable solution structure for a recurring software design problem whose implementation can vary across languages and frameworks.

A design pattern is a named, reusable solution structure for a recurring software design problem. Its core solution can be reused without repeating the implementation exactly, helping designs adapt as software changes. section 9.1.3 section 9.0

Patterns are not tied to one programming language. Implementations change with languages and frameworks; Java 8, for example, enables different implementations through functional-style programming. section 9.1.3

Common patterns connect reusable structures with broader design principles:

  • Singleton centralizes state by ensuring one class instance and a global access point. section 9.1.3
  • Builder separates complex object construction from representation and supports step-by-step configuration. section 9.1.3
  • Strategy encapsulates interchangeable algorithm families, allowing new behavior without changing existing code. section 9.1.3
  • Circuit Breaker addresses distributed-system resilience. section 9.1.3

A condition-heavy calculation

A shipping calculation branches across express delivery, holidays, international orders, and country codes. Such recurring design problems are candidates for a named reusable structure rather than repeated ad hoc logic. section 9.1.3

Table 9.2 Useful design patterns
Pattern
Description
Relation to SOLID principles
Singleton
Ensures only one instance of a class exists and provides a global access point.
Supports the Single Responsibility Principle by centralizing state.
Builder
Separates object construction from its representation, allowing step-by-step creation of complex objects. See example in chapter 4.
Supports the Open/Closed Principle by allowing new configurations without modifying existing code.
Strategy
Defines a family of algorithms, encapsulates each one, and makes them interchangeable at runtime. See example in chapter 3.
Exemplifies the Open/Closed and Dependency Inversion principles by encapsulating algorithms behind a common interface and allowing new behaviors without changing existing code.
Factory
Encapsulates object creation logic, delegating instantiation to dedicated classes.
Demonstrates the Dependency Inversion Principle by decoupling high-level code from specific implementations and supporting the Open/Closed Principle by allowing new objects to be created without modifying existing code.
Decorator
Dynamically adds new behavior to objects without modifying their code. See example in chapter 7.
Supports the Open/Closed Principle by adding behavior to an object without altering its source code.
Observer
Establishes a one-to-many relationship where objects automatically update when a subject changes.
Demonstrates the Open/Closed and Dependency Inversion principles by letting subjects and observers interact through abstractions, allowing new observers without modifying existing code.

Compare well-known patterns with their descriptions and relationships to SOLID principles. section 9.1.3

How The Art of Code covers it

How deep it goes
Defines pattern intent, catalog examples, and language variation, but does not provide a complete implementation of each pattern.
Examples
Uses Singleton, Builder, Strategy, Factory, Circuit Breaker, and a condition-heavy shipping calculation as examples.
What you can do after
Apply named reusable solutions to recurring design problems while varying their implementations across languages and frameworks.
How it connects
Connects design patterns with durability, SOLID principles, resilience, distributed systems, and functional-style programming.

Also explained in

Compare how 7 books explain design pattern →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of The Art of Code. The section links point to the parts of the book it draws on.