Friday, April 16, 2010

Disadvantage of inheritance

i. Main disadvantage of using inheritance is that the two classes (base and inherited class) get tightly coupled.
ii. This means one cannot be used independent of each other.
iii. Also with time, during maintenance adding new features both base as well as derived classes are required to be changed.
iv. i.e. If a method signature is changed then we will be affected in both cases (inheritance & composition)


v. Either of both of them are changed to accommodate changes.
vi. This further makes them more tightly coupled and lots of contextual information tends to be added.
vii. If a method is deleted in the "super class" or aggregate, then we will have to re-factor in case of using that method.Here things can get a bit complicated in case of inheritance because our programs will still compile, but the methods of the subclass will no longer be overriding superclass methods. These methods will become independent methods in their own right.

1 comment: