Home > Net >  Why is inheritance So important, when you can Just create different classes and use them separately
Why is inheritance So important, when you can Just create different classes and use them separately

Time:05-08

I have been learning about Object-Oriented Programming. I am currently learning about inheritance but don't know where to apply it and use it. I really want to know about it because I strictly focus on the Application of different functionalities and how to use them.

CodePudding user response:

Inheritance is incredibly useful for encapsulation. It promotes the reusability of code without rewriting the code and it is even helpful in decreasing the time complexity of the program which can be really advantageous in competitive coding.

CodePudding user response:

Inheritance is mostly used to share functionality between kindred classes - that's even why the word for it is inheritance. Your child class inherits methods and fields of the parent class and therefore has access to the same functionality as the parent class.

The primary use case is to avoid code duplication or to make the design of complex objects a bit easier - but this is already well covered and doesn't need another elaboration.

But in the end, software architecture and design is always something which is subject to opinions - there may be best practices which really make sense to adhere to but on the other hand: You don't always have the time to design and code clean software.

  •  Tags:  
  • oop
  • Related