CStaff and CVeterinarian are special kinds of CEmployee in our example, which is why they inherit from CEmployee in Figure 9. When objects transmute from one subclass to another, this is a sign that we might have objects serving multiple roles. We don't expect CVeterinarian objects to become CStaff objects, but we can easily predict that CStaff and CVeterinarian objects will sometimes play the role of CClient objects. Clients and employees are special roles for people objects. Composition is better when objects need to transmute to objects of another class.
Inheritance is appropriate when one class extends another class.
Conclusion Inheritance has important uses. It provides strong encapsulation of functionality against classes outside its object hierarchy. It promotes reuse by capturing commonalities in a base class and then extending those common features in descendant classes. Composition also provides encapsulation and reuse. Encapsulation is stronger in composition, because changes in one class are less likely to ripple throughout an object hierarchy.