Implementing the pImpl pattern
In order to implement the pImpl pattern, we will need to revisit the typical header and source file composition. We will then replace the private members in a typical class definition with a pointer to the implementation, taking advantage of an association. The implementation will be encapsulated within a nested class of our target class. Our pImpl pointer will delegate all requests to our associated object that provides the inner class details or implementation.
The inner (nested) class will be referred to as the implementation class. The original, now outer, class will be referred to as the target or interface class.
We will start by reviewing the typical (non-pImpl pattern) file composition containing class definitions and member function definitions.
Organizing file and class contents to apply the pattern basics
Let’s first review the organization strategy of the typical C++ class with respect to file placement regarding the class...