Disadvantages of Inheritance
Hello friend,
I need your help to solve my confusion regarding the inheritance. The inheritance concept of object oriented programming basically used for make reusability of the program code. But I want to be aware about the disadvantages of using inheritance. If you knows any disadvantages of 'Inheritance', then please let me know that. I would appreciate your help.
Re: Disadvantages of Inheritance
Hi friend,
According to me the disadvantage of using inheritance is that, it brings vulnerability in program. Multiple inheritance may create serious problems in following situation:
- The members management of the same name inherited from parent classes
- The management of the repetition inheritance.
Re: Disadvantages of Inheritance
Multiple inheritance can pose difficult problems, so there is controversy over whether its benefits outweigh its disadvantages. Java has the following compromise: it allows a class to inherit interfaces more than one parent (that is to say that we can specify that a class should have all the methods exposed outside its parent interface, and allow the compiler 's sure), but it can inherit methods and data from a single parent class. Languages such as Microsoft C # and Visual Basic implement this same approach.
Re: Disadvantages of Inheritance
The main problem with inheritance comes from entities as a method or member that is present several times in the ancestors of a class. For example if you define a class App for portable devices powered by a battery, a class Such for mobile phones that inherits AppA class Ordn for laptops that inherits App and finally a class TelOrdn used for mobile computers that also inherits Ordn and Such. So it is not clear whether the bodies TelOrdn contain one or two batteries and under what name to differentiate them.
Re: Disadvantages of Inheritance
The inheritance turns into disadvantage when it comes to compile or run programs using classes in multiple inheritance. Indeed in the case of polymorphic method call (when one method has several versions in classes inheriting from each other), we must find which method should be executed. As part of a single inheritance, the ancestors of a class make a list and it is easy to create a table of dynamic binding allows a simple test to find the correct version. As part of a multiple inheritance the ancestors of a class now form a graph and the table of dynamic binding is more difficult to create.
Re: Disadvantages of Inheritance
OOP provides the virtual inheritance as a complementary tool less ambitious. The refinement of the semantic mechanisms brought into play in multiple inheritance has discouraged many users and explains the bad reputation he has gained in part from the developer community. Nevertheless algorithms exist for this compilation, it is possible to resolve multiple inheritance with the same cost to run the simple inheritance. Obviously it is impossible to use these techniques with languages that are not compiled, in which case it must traverse the inheritance graph at runtime, which can be quite long.