O'Reilly logo

C++ Common Knowledge: Essential Intermediate Programming by Stephen C. Dewhurst

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Item 30. Factory Method

A high-level design often requires the creation of an object of the “appropriate” type, based on the type of an existing object. For example, we may have a pointer or reference to an Employee object of some kind, and we need to generate the appropriate kind of HRInfo object for that type of Employee, as shown in Figure 8.

Figure 8. Pseudoparallel hierarchies. How should we map an employee to its corresponding human resources information?

image

Here we have almost parallel Employee and HRInfo hierarchies. Salary and Hourly employees require the generation of an StdInfo object whereas a Temp requires a TempInfo object.

The high-level ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required