Design Patterns in C++
5 Topics
1
Singleton Pattern
Implement the Singleton pattern in C++ using Meyers' Singleton to guarantee thread safety.
Meyers' Singleton thread safety guarantees (C++11), deleting copy constructors, and Singleton testing trade-offs.
2
Factory Pattern
Decouple object creation from client code using Factory Method patterns and smart pointers.
Polymorphism, using std::unique_ptr for return types, and enforcing the Open-Closed Principle.
3
Observer Pattern
Design reactive subscription models in C++ using std::weak_ptr to prevent reference cycles.
Managing object lifetimes, using weak_ptr to prevent circular reference leaks, and thread-safe notification loops.
4
Strategy Pattern
Implement the Strategy pattern using polymorphism or functional std::function wrappers.
Swapping algorithms at runtime, virtual table costs, and comparing static templates vs. dynamic strategies.
5
Builder Pattern
Construct complex objects stepwise using fluent interfaces and method chaining.
Method chaining using reference returns, managing partial instantiation states, and validating invariants on build.