GDB Discussion Topic
Suppose you are working as a software developer in a company. You have been given a task to develop a software system design for some real world scenario. One of the basic activities of any software system design is to establish relationships between classes. Suppose at the stage of creating relationships for some classes, you have to choose either inheritance or composition as these are two fundamental ways to relate classes by achieving feature of code re-usability. Being a developer, for what reasons, would you prefer one technique to the other keeping in mind the reusability factor? Support your answer with solid reasons.
Inheritance is an object-oriented programming feature by which derived class can inherit accessible attributes and member functions of base class
using inheritance we can increase the reusability.
Features or Advantages of Inheritance:
Inheritance helps the code to be reused in many
situations. The base class is defined and once it is
compiled, it need not be reworked. Using the concept of
inheritance, the programmer can create as many derived
classes from the base class as needed while adding specific
features to each derived class as needed.
---Saves Time and Effort:
The above concept of reusability achieved by inheritance
saves the programmer time and effort. Since the main code
written can be reused in various situations as needed.
---Increases Program Structure which results in greater
inheritance has the following main advantages:
we can extend the already made classes by adding some new
it is easy to debug a program when divided in parts.
inheritance provides an opportunity to capture the problem
Definitely Composition method
Reasons: easy to change the front-end and back-end class as compared to the superclass.
Provides strong encapsulation.