Implementing Patterns and Idioms
Design patterns are general reusable solutions that can be applied to common problems that appear in software development. Idioms are patterns, algorithms, or ways to structure the code in one or more programming languages. A great number of books have been written on design patterns. This chapter is not intended to reiterate them, but rather to show how to implement several useful patterns and idioms, with a focus on readability, performance, and robustness, in terms of modern C++.
The recipes included in this chapter are as follows:
- Avoiding repetitive
if...else
statements in factory patterns - Implementing the pimpl idiom
- Implementing the named parameter idiom
- Separating interfaces from implementations with the non-virtual interface idiom
- Handling friendship with the attorney-client idiom
- Static polymorphism with the curiously recurring template pattern
- Implementing a thread-safe singleton...