Monday, December 14, 2015

Superclasses and Subclasses



   >>> The superclass, or parent class, contains all the attributes and behaviours that are common to classes that inherit from it.

   >>> For example, in the case of the Mammal class, all mammals have similar attributes such as eyeColor and hairColor as well as behaviours such as generateInternalHeat and growHair. All mammals have these attributes and behaviours, so it is not necessary to duplicate them down the inheritance tree for each type of mammal.

   >>> Thus, the dog and cat classes inherit all those common attributes and behaviours from the mammal class., The class is considered the superclass of the dog and the cat subclasses, or child classes.

   >>> Inheritance provides a rich set of design advantages. When you're designing a cat class, the mammal class provides much of the functionality needed. By inheriting from the mammal object, cat already has all the attributes and behaviours that make it a true mammal. To make it more specifically a cat type of mammal, the cat class must include  any attributes or behaviours that pertain solely to cat.

   >>> Subclasses can also add new members.

   >>> In fact, inheritance is an "is - a relationship"

   >>> To create a subclass is Specialization, to factor out common parts of derived classes into a common base ( or parent) is generalization. 

No comments:

Post a Comment