C++ Software Design

Book description

Good software design is essential for the success of your project, but designing software is hard to do. You need to have a deep understanding of the consequences of design decisions and a good overview of available design alternatives. With this book, experienced C++ developers will get a thorough, practical, and unparalleled overview of software design with this modern language.

C++ trainer and consultant Klaus Iglberger explains how you can manage dependencies and abstractions, improve changeability and extensibility of software entities, and apply and implement modern design patterns to help you take advantage of today's possibilities. Software design is the most essential aspect of a software project because it impacts the software's most important properties: maintainability, changeability, and extensibility.

  • Learn how to evaluate your code with respect to software design
  • Understand what software design is, including design goals such as changeability and extensibility
  • Explore the advantages and disadvantages of each design approach
  • Learn how design patterns help solve problems and express intent
  • Choose the right form of a design pattern to get the most out of its advantages

Publisher resources

View/Submit Errata

Table of contents

  1. Preface
    1. Why I Wrote This Book
    2. What This Book Is About
      1. Software Design
      2. Modern C++
      3. Design Patterns
    3. Who This Book Is For
    4. How This Book Is Structured
    5. Conventions Used in This Book
    6. Using Code Examples
    7. O’Reilly Online Learning
    8. How to Contact Us
    9. Acknowledgments
  2. 1. The Art of Software Design
    1. Guideline 1: Understand the Importance of Software Design
      1. Features Are Not Software Design
      2. Software Design: The Art of Managing Dependencies and Abstractions
      3. The Three Levels of Software Development
      4. The Focus on Features
      5. The Focus on Software Design and Design Principles
    2. Guideline 2: Design for Change
      1. Separation of Concerns
      2. An Example of Artificial Coupling
      3. Logical Versus Physical Coupling
      4. Don’t Repeat Yourself
      5. Avoid Premature Separation of Concerns
    3. Guideline 3: Separate Interfaces to Avoid Artificial Coupling
      1. Segregate Interfaces to Separate Concerns
      2. Minimizing Requirements of Template Arguments
    4. Guideline 4: Design for Testability
      1. How to Test a Private Member Function
      2. The True Solution: Separate Concerns
    5. Guideline 5: Design for Extension
      1. The Open-Closed Principle
      2. Compile-Time Extensibility
      3. Avoid Premature Design for Extension
  3. 2. The Art of Building Abstractions
    1. Guideline 6: Adhere to the Expected Behavior of Abstractions
      1. An Example of Violating Expectations
      2. The Liskov Substitution Principle
      3. Criticism of the Liskov Substitution Principle
      4. The Need for Good and Meaningful Abstractions
    2. Guideline 7: Understand the Similarities Between Base Classes and Concepts
    3. Guideline 8: Understand the Semantic Requirements of Overload Sets
      1. The Power of Free Functions: A Compile-Time Abstraction Mechanism
      2. The Problem of Free Functions: Expectations on the Behavior
    4. Guideline 9: Pay Attention to the Ownership of Abstractions
      1. The Dependency Inversion Principle
      2. Dependency Inversion in a Plug-In Architecture
      3. Dependency Inversion via Templates
      4. Dependency Inversion via Overload Sets
      5. Dependency Inversion Principle Versus Single-Responsibility Principle
    5. Guideline 10: Consider Creating an Architectural Document
  4. 3. The Purpose of Design Patterns
    1. Guideline 11: Understand the Purpose of Design Patterns
      1. A Design Pattern Has a Name
      2. A Design Pattern Carries an Intent
      3. A Design Pattern Introduces an Abstraction
      4. A Design Pattern Has Been Proven
    2. Guideline 12: Beware of Design Pattern Misconceptions
      1. Design Patterns Are Not a Goal
      2. Design Patterns Are Not About Implementation Details
      3. Design Patterns Are Not Limited to Object-Oriented Programming or Dynamic Polymorphism
    3. Guideline 13: Design Patterns Are Everywhere
    4. Guideline 14: Use a Design Pattern’s Name to Communicate Intent
  5. 4. The Visitor Design Pattern
    1. Guideline 15: Design for the Addition of Types or Operations
      1. A Procedural Solution
      2. An Object-Oriented Solution
      3. Be Aware of the Design Choice in Dynamic Polymorphism
    2. Guideline 16: Use Visitor to Extend Operations
      1. Analyzing the Design Issues
      2. The Visitor Design Pattern Explained
      3. Analyzing the Shortcomings of the Visitor Design Pattern
    3. Guideline 17: Consider std::variant for Implementing Visitor
      1. Introduction to std::variant
      2. Refactoring the Drawing of Shapes as a Value-Based, Nonintrusive Solution
      3. Performance Benchmarks
      4. Analyzing the Shortcomings of the std::variant Solution
    4. Guideline 18: Beware the Performance of Acyclic Visitor
  6. 5. The Strategy and Command Design Patterns
    1. Guideline 19: Use Strategy to Isolate How Things Are Done
      1. Analyzing the Design Issues
      2. The Strategy Design Pattern Explained
      3. Analyzing the Shortcomings of the Naive Solution
      4. Comparison Between Visitor and Strategy
      5. Analyzing the Shortcomings of the Strategy Design Pattern
      6. Policy-Based Design
    2. Guideline 20: Favor Composition over Inheritance
    3. Guideline 21: Use Command to Isolate What Things Are Done
      1. The Command Design Pattern Explained
      2. The Command Design Pattern Versus the Strategy Design Pattern
      3. Analyzing the Shortcomings of the Command Design Pattern
    4. Guideline 22: Prefer Value Semantics over Reference Semantics
      1. The Shortcomings of the GoF Style: Reference Semantics
      2. Reference Semantics: A Second Example
      3. The Modern C++ Philosophy: Value Semantics
      4. Value Semantics: A Second Example
      5. Prefer to Use Value Semantics to Implement Design Patterns
    5. Guideline 23: Prefer a Value-Based Implementation of Strategy and Command
      1. Introduction to std::function
      2. Refactoring the Drawing of Shapes
      3. Performance Benchmarks
      4. Analyzing the Shortcomings of the std::function Solution
  7. 6. The Adapter, Observer, and CRTP Design Patterns
    1. Guideline 24: Use Adapters to Standardize Interfaces
      1. The Adapter Design Pattern Explained
      2. Object Adapters Versus Class Adapters
      3. Examples from the Standard Library
      4. Comparison Between Adapter and Strategy
      5. Function Adapters
      6. Analyzing the Shortcomings of the Adapter Design Pattern
    2. Guideline 25: Apply Observers as an Abstract Notification Mechanism
      1. The Observer Design Pattern Explained
      2. A Classic Observer Implementation
      3. An Observer Implementation Based on Value Semantics
      4. Analyzing the Shortcomings of the Observer Design Pattern
    3. Guideline 26: Use CRTP to Introduce Static Type Categories
      1. A Motivation for CRTP
      2. The CRTP Design Pattern Explained
      3. Analyzing the Shortcomings of the CRTP Design Pattern
      4. The Future of CRTP: A Comparison Between CRTP and C++20 Concepts
    4. Guideline 27: Use CRTP for Static Mixin Classes
      1. A Strong Type Motivation
      2. Using CRTP as an Implementation Pattern
  8. 7. The Bridge, Prototype, and External Polymorphism Design Patterns
    1. Guideline 28: Build Bridges to Remove Physical Dependencies
      1. A Motivating Example
      2. The Bridge Design Pattern Explained
      3. The Pimpl Idiom
      4. Comparison Between Bridge and Strategy
      5. Analyzing the Shortcomings of the Bridge Design Pattern
    2. Guideline 29: Be Aware of Bridge Performance Gains and Losses
      1. The Performance Impact of Bridges
      2. Improving Performance with Partial Bridges
    3. Guideline 30: Apply Prototype for Abstract Copy Operations
      1. A Sheep-ish Example: Copying Animals
      2. The Prototype Design Pattern Explained
      3. Comparison Between Prototype and std::variant
      4. Analyzing the Shortcomings of the Prototype Design Pattern
    4. Guideline 31: Use External Polymorphism for Nonintrusive Runtime Polymorphism
      1. The External Polymorphism Design Pattern Explained
      2. Drawing of Shapes Revisited
      3. Comparison Between External Polymorphism and Adapter
      4. Analyzing the Shortcomings of the External Polymorphism Design Pattern
  9. 8. The Type Erasure Design Pattern
    1. Guideline 32: Consider Replacing Inheritance Hierarchies with Type Erasure
      1. The History of Type Erasure
      2. The Type Erasure Design Pattern Explained
      3. An Owning Type Erasure Implementation
      4. Analyzing the Shortcomings of the Type Erasure Design Pattern
      5. Comparing Two Type Erasure Wrappers
      6. Interface Segregation of Type Erasure Wrappers
      7. Performance Benchmarks
      8. A Word About Terminology
    2. Guideline 33: Be Aware of the Optimization Potential of Type Erasure
      1. Small Buffer Optimization
      2. Manual Implementation of Function Dispatch
    3. Guideline 34: Be Aware of the Setup Costs of Owning Type Erasure Wrappers
      1. The Setup Costs of an Owning Type Erasure Wrapper
      2. A Simple Nonowning Type Erasure Implementation
      3. A More Powerful Nonowning Type Erasure Implementation
  10. 9. The Decorator Design Pattern
    1. Guideline 35: Use Decorators to Add Customization Hierarchically
      1. Your Coworkers’ Design Issue
      2. The Decorator Design Pattern Explained
      3. A Classic Implementation of the Decorator Design Pattern
      4. A Second Decorator Example
      5. Comparison Between Decorator, Adapter, and Strategy
      6. Analyzing the Shortcomings of the Decorator Design Pattern
    2. Guideline 36: Understand the Trade-off Between Runtime and Compile Time Abstraction
      1. A Value-Based Compile Time Decorator
      2. A Value-Based Runtime Decorator
  11. 10. The Singleton Pattern
    1. Guideline 37: Treat Singleton as an Implementation Pattern, Not a Design Pattern
      1. The Singleton Pattern Explained
      2. Singleton Does Not Manage or Reduce Dependencies
    2. Guideline 38: Design Singletons for Change and Testability
      1. Singletons Represent Global State
      2. Singletons Impede Changeability and Testability
      3. Inverting the Dependencies on a Singleton
      4. Applying the Strategy Design Pattern
      5. Moving Toward Local Dependency Injection
  12. 11. The Last Guideline
    1. Guideline 39: Continue to Learn About Design Patterns
  13. Index
  14. About the Author

Product information

  • Title: C++ Software Design
  • Author(s): Klaus Iglberger
  • Release date: September 2022
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9781098113162