When to use Inheritance? Assignment Help

Assignment Help: >> Inheritance - When to use Inheritance?

When to Use Inheritance?

The given principles have to be followed to promote the use of inheritance in programming which leads to code reuse, simple of code maintenance and extension:

  1. The most general use of inheritance and sub classing is for specialization, that is the most obvious and direct use of this rule. If two abstract concepts A and B are being considered and the sentence A is a B makes sense then it is possibly correct in making A as a subclass of B. Instances car is a vehicle, triangle is a shape and many more.
  2. Another often use of inheritance is to guarantee in which classes manage a certain common interface; which is, they implement the similar methods. The parent class could be a combination of implemented operations and operations which are to be implemented in the child classes. Frequently, there is no interface modification among the super type and subtype - the child implements the behaviour define in the alteration of its parent class. This characteristic has much significance along with pure virtual function.
  3. By using generalization method, a subclass extends the behaviour of the super class to create a more common kind of object. This is frequent applicable whenever one is building on a base of existing classes which should not or cannot be changed.
  4. Although subclassing for generalization modifies or expands on the existing functionality of a class, subclassing for extension adds completely new abilities. Subclassing for extension could be distinguished from subclassing for generalization in derivation. A Generalization must override at least one method from the parent, and the functionality is tied to which of the parent while extension easily adds new methods to those of the parent and functionality is less strongly tied to the existing parent methods.
  5. Within subclassing for limitation, the subclass behavior is more restricted than the behavior of the superclass. Such as subclassing for generalization, subclassing for limitation occurs most often when a programmer is building on a base of existing classes which should not or cannot be modified.
  6. Subclassing for variance is useful whenever two or more classes have same implementations, but there does not seem to be any hierarchical relationship is to factor out the general code into an abstract class and derive the classes from these common ancestors.
  7. Subclassing through combination occurs whenever a subclass represents a merged feature from two or more parent classes.
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd