Factory-like patterns in C++
There are many variations of the basic Factory patterns used in C++ to address specific design needs and constraints. In this section, we will consider several of them. This is by no means an exclusive list of factory-like patterns in C++, but understanding these variants should prepare the reader for combining the techniques that they have learned from this book to address various design challenges related to object factories.
Polymorphic copy
So far, we have considered factory alternatives to the object constructor—either the default constructor or one of the constructors with arguments. However, a similar pattern can be applied to the copy constructor—we have an object, and we want to make a copy.
This is a similar problem in many ways—we have an object that’s accessed through the base class pointer, and we want to call its copy constructor. For the reasons we discussed earlier, not the least of which is that the...