In this first part of a three-part series, we'll take a look at inheritance and composition and what roles they play in object model design. Inheritance Inheritance is one way of extending object design. It's a mechanism for extending one object by allowing one class to accept all of the attributes, associations, and methods in another class. The inheriting class, called a subclass, can add to the features of its ancestor. Figure 1 shows an example of inheritance from a veterinary management application.
Medical charts contain many entries.
Not all entries are alike, but they all contain basic elements, such as patient ID, date, time, person making the notation, etc. The CChartEntry class declares these common attributes, and any common methods. The subclasses, CVaccination , CLabResult , CPhysicalExam , add their own common attributes and methods. An example of inheritance. The code in Figure 2 shows the inheritance mechanism from CChartEntry to CVaccination in Figure 1.