Saturday, 2 October 2010

advantages and disadvantages of inheritance



Reasons for the usage of inheritance:
Specialization:A new class is derived from the base class and the new class can add data members and member function specific to it. i.e. new class is a specialization of the base class.
Generalization:When two or more classes have similar properties, then this similarity can be combined together into a common base class, and the common class can be treated as a generalized class.
Interface: Used by the base class to define interface, but does not implement some or all parts of it.
Advantages:
In hierarchical relationships inheritance makes the developpment model clones to real life object model.
Reusability:The public members of base class can be reused by derived class without rewriting them.
Datahiding:The base class can control the access of some data so that they can not be modified by the derived class.
Extensibility:Extending the base class properties by the derived class to generate more dominate object.
Disadvcantages:
1.      Objects when used for invoking member functions create more compiler overheads.
2.      Memory allocated to unused data elements will not be utilized.
Inheritance if not used correctly leads a program to be more complicated.



Types of Inheritance

No comments:

Post a Comment