Thursday 28 February 2013

Need of Abstract classes and Abstract Methods

The concept of abstract classes is an extension to the concept of inheritance. In inheritance the parent classes can be defined with attributes that are commonly required under multiple child classes providing reusability.

FIGURE
  • Rectangle
  • Circle
  • Triangle
  • Cone
In the above case when we want to define different entities representing various figures like Rectangle, Traingle, Circle, Cone etc in such cases first we identify the attributes that are commonly required and put them under a parent class.
The class Figure as it is the parent provides the attributes commonly required to all figures given reusability. Along with this we can also define any abstract in the parent class figure so that the child classes will implement the abstract members which is a restriction for the child classes and cannot escape from it.
   

No comments:

Post a Comment