Concept: Inheritance


Contents

  1. Introduction
  2. Definition
  3. Rules for Defining Sub-classes
  4. Dealing With Multiple Inheritance

1. Introduction

The concept of inheritance is used in the context of object oriented modeling. Its key objective is to reduce the redundancy in object models by arranging classes with similar attributes and operations in a hierarchy.


2. Definition

Inheritance hierarchyInheritance is a type of relationship among classes, wherein one class shares the structure or behaviour defined in one (single inheritance) or more (multiple inheritance) other classes. Inheritance defines a "kind of" hierarchy among classes in which a sub class inherits from one or more super-classes; a sub-class typically augments or redefines the existing structure and behaviour of its super-classes. [25]

The example models a fragment of a complaint resolution system. It models the fact that a complaint can either be about the company's product or a product purchased by the company from a supplier. The former complaint would originate from a customer, the latter would originate from within the company itself. In both cases the complainant details, date and description of complaint are recorded. These attributes therefore remain with the super-class "complaint" which models the general case. In the special case of the company product however invoice, credit note and product information needs to be recorded. These attributes are therefore modeled as being unique to the "company product" sub-class. In the case of the supplier product, supplier information, order number, supplier invoice and supplier product information must be recorded. These attributes are therefore unique to the "supplier product" sub-class. In both cases the attributes of the super-class "complaint" plus the attributes of the individual sub-classes completely define the attributes of that sub-class.

In both cases the complaint needs to be recorded and resolved. These operations therefore remain with the super-class "complaint". In the case of a sub-class "company product" a credit note needs to be recorded. This operation therefore augments the operations of this sub-class. As with the attributes the operations of the super-class "complaint" plus the operations of the individual sub-classes completely define the operations of that sub-class.

The sub-classes are said to inherit the attributes and operations of their super-class.


3. Rules for Defining Sub-classes

  • A sub-class is a specialisation of its parent class
  • All sub-classes inherit the super-class attributes & operations
  • Each sub-class has unique attributes & operations
  • A sub-class may override features of a parent class by defining one with the same name


4. Dealing With Multiple Inheritance

Multiple inheritance permits a class to have more than one super-class and to inherit features from all parents.
  • A class may inherit features from more than one super-class
  • If parent classes have the same features they are inherited only once
  • Conflicts among parallel features must be explicitly resolved by disabling the inheritance of a specific feature

In the example an amphibious vehicle has the characteristics of both a land vehicle and a water vehicle. It therefore exhibits multiple inheritance from both these classes.


Software Engineering Web
Copyright
ã 1997 Chambers & Associates Pty Ltd
Module: 104 v1.0 c_inhert.htm
Updated: July 02, 2006