Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

• in C++ What is the significance of the concept of inheritance within the conce

ID: 3821846 • Letter: #

Question

• in C++ What is the significance of the concept of inheritance within the concept of object oriented programming? How does the concept of inheritance improve on the traditional programming model?
• Provide a programming problem in which inheritance should be used (You do not need to write codes for this discussion. Instead, describe the programming problem and explain why inheritance should be used).
• Research the concept of Polymorphism and, again, provide a programming problem in which polymorphism should be used.

Explanation / Answer

Please see my answers inline below.

What is the significance of the concept of inheritance within the concept of object oriented programming? How does the concept of inheritance improve on the traditional programming model?

In object oriented programming model, the concept of inheritance enables derived class objects to inherit data (properties) and / or behavior (methods) of base class objects. Inheritance helps us to model related objects in a hierarchy.

Inheritance concept reflects is a relationship which is commonly seen in real world objects. e.g. Apple is a Fruit.

Further, inheritance enables derived objects to override and change the default behavior inherited from base class objects.

Compared to traditional programming model, using inheritance has following benefits in software development:

Provide a programming problem in which inheritance should be used.

For example, we want to build a system which maintains information about various employees (e.g. Developer, Tester, Manager) working in a software company.

Inheritance should be used in building this system to model data and behavior of Employee (base class), Developer (derived class of Employee), Tester (derived class of Employee) and Manager (derived class of Employee).

The company needs to maintain several pieces of similar information for each employee such as first name, last name, office address, email, telephone number etc. Such information can be encapsulated in the Employee base class.

Unlike a developer or tester, a manager typically has one or more employees reporting to him or her. Reporting details is specific information which should be encapsulated within the Manager derived class.

Research the concept of Polymorphism and, again, provide a programming problem in which polymorphism should be used.

Polymorphism means many forms. It is applicable when there is a hierarchy of classes related by inheritance. A base class reference can be used to refer to one or more derived class objects. Invoking a method using base class reference results in a method to be executed based on the type of the object.

For example, we want to develop a program which prints area of a list of shapes. Say, this program involves developing Shape (base class), Rectangle (derived class of Shape), Circle (derived class of Shape) and Triangle (derived class of Shape) classes. Each of these classes provides a method (namely, area) to compute area of a given shape. This program can allow creation of a list of several shapes (Rectangle / Circle / Triangle) and then it computes and prints the area of each shape. This is easily achieved through polymorphism by using a base class reference to iterate through the list of shapes and invoking area method on each shape to compute and print area of given shape.