On line 274, this value is fed to the PartsList’s Find()method, and if no match is
found, the number is inserted (line 276); otherwise, an informative error message is
printed (starting on line 280).
Note that PartsCatalogdoes the actual insert by calling Insert()on its member vari-
able,pl, which is a PartsList. The mechanics of the actual insertion and the maintenance
of the linked list, as well as searching and retrieving from the linked list, are maintained in
the aggregated PartsListmember of PartsCatalog. No reason exists for PartsCatalog
to reproduce this code; it can take full advantage of the well-defined interface.
This is the essence of reusability within C++:PartsCatalogcan reuse the PartsList
code, and the designer of PartsCatalogis free to ignore the implementation details of
PartsList. The interface to PartsList(that is, the class declaration) provides all the
information needed by the designer of the PartsCatalogclass.
562 Day 16
If you want more information about PartsList, review the Week 2 in
Review listing and analysis!
NOTE
Private Inheritance ..............................................................................................
If PartsCatalogneeded access to the protected members of PartsList(in this case,
none exist), or needed to override any of the PartsListmethods, then PartsCatalog
would be forced to inherit from PartsList.
Because a PartsCatalogis not a PartsListobject, and because you don’t want to
expose the entire set of functionality of PartsListto clients of PartsCatalog, you
would need to use private inheritance. Private inheritance allows you to inherit from
another class and to keep the internals of that class completely private to your derived
class.
The first thing to know about private inheritance is that all the base member variables
and functions are treated as if they were declared to be private, regardless of their actual
access level in the base. Thus, to any function that is not a member function of
PartsCatalog, every function inherited from PartsListis inaccessible. This is critical:
Private inheritance does not involve inheriting interface, only implementation.
To clients of the PartsCatalogclass, the PartsListclass is invisible. None of its inter-
face is available to them: They can’t call any of its methods. They can call PartsCatalog
methods; however,PartsCatalogmethods can then access all of PartsListbecause
PartsCatalogis derived from PartsList. The important thing here is that the
PartsCatalogisn’t a PartsList, as would have been implied by public inheritance. It is