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. 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 gain most 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 for Artificial Coupling
      3. Logical vs. 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 for Violating Expectations
      2. The Liskov Substitution Principle
      3. Criticism about 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 Plugin Architecture
      3. Dependency Inversion via Templates
      4. Dependency Inversion via Overload Sets
      5. Dependency Inversion Principle vs. 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 Neither Limited to Object-Oriented Programming nor 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 Visitors 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 Visitors
      1. Introduction to std::variant
      2. Refactoring the Drawing of Shapes as Value-Based, Non-Intrusive Solution
      3. Performance Benchmarks
      4. Analyzing the Shortcomings of the std::variant Solution
    4. Guideline 18: Beware the Performance of Acyclic Visitors
  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 Commands 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 to 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 vs. 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 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 the Performance Gains and Losses of Bridges
      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 Non-Intrusive 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: Know about the Optimization Potential of Type Erasure
      1. Small Buffer Optimization (SBO)
      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 Non-Owning Type Erasure Implementation
      3. A More Powerful Non-Owning 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 Tradeoff 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 Towards Local Dependency Injection
  12. 11. The Last Guideline
    1. Guideline 39: Continue to Learn About Design Patterns
  13. About the Author

Product information

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