There's more...

The feature that is most frequently associated with OOP is inheritance, which is the ability to define a new class as a modified version of an already existing class. The main advantage of inheritance is that you can add new methods to a class without having to change the original definition.

The original class is often referred to as the parent class and the derived class, subclass. Inheritance is a powerful feature, and some programs can be written much more easily and concisely, providing the possibility to customize the behavior of a class without modifying the original class. The very fact that the inheritance structure can reflect that of the problem can, in some cases, make the program easier to understand.

However (to put the user on guard!), inheritance can make it more difficult to read the program. This is because, when invoking a method, it is not always clear where this has been defined within the code that must be traced within multiple modules, instead of being in a single well-defined place.

Many of the things that can be done with inheritance can usually be managed elegantly even without it, so it is appropriate to only use inheritance if the structure of the problem requires it. If used at the wrong time, then the harm inheritance can cause can outweigh the benefits of using it.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.19.30.232