CS304 GDB Solution
#1
CS304 Object Oriented Programming
GDB Fall 2016

The Problem:
The main purpose of inheritance is reuse of code. Multiple-inheritance is more productive in terms of reuse of code than single inheritance. But all of this comes with a cost. Suppose we have a class Person which is inherited by Teacher and Student. Both Teacher and Student are further inherited by Teacher Assistant thus resulting in multiple-inheritance.

Question: Would you select multiple-inheritance in your code along with its intrinsic cost or do the other ways? Justify with solid reasons in either case.


Answer: In the scenario mentioned, I would not use multiple-inheritance in my code. Because multiple-inheritance is prone to errors. The diamond problem is an example. If multiple-inheritance is used, the new Teacher-Assistant class will have two copies of many same functions that are inherited by the Teacher and Student Classes from Person Class, calling such functions results in ambiguity.
One solution for the problem would be virtual inheritance. In virtual inheritance we use the word virtual in the deceleration of the classes and when we inherit with virtual inheritance, we are guaranteed to get only a single instance of the common base class. So this will solve many problems in our code and will be the best practice to use here.
#2
a.salam
#3
(07-27-2017, 08:24 PM)abrish.khan Wrote: a.salam

WaAlaikum Assalam. Welcome to ForumVU Smile
  


Possibly Related Threads...
Thread Author Replies Views Last Post
  CS304 Assignment 2 Solution Fall 2017 Admin 0 89 11-23-2017, 09:08 PM
Last Post: Admin
  CS304 Assignment 1 Solution Fall 2017 Pakistani 0 1,188 11-06-2017, 10:58 AM
Last Post: Pakistani
  CS304 Quiz 1 Questions Solved Pakistani 1 601 05-22-2017, 10:33 PM
Last Post: Iram Rana
  CS304 Assignement 1 full Solution 2017 Rubaisha(Moody Girl) 0 660 04-28-2017, 09:34 PM
Last Post: Rubaisha(Moody Girl)
  CS304 Assignment 1 Solution - Fall 2016 Admin 1 1,394 11-10-2016, 08:45 AM
Last Post: Pakistani
  CS304 All Current Final Term Papers 20 August 2016 to 02 September 2016 Rubaisha(Moody Girl) 2 1,113 08-28-2016, 06:23 PM
Last Post: Rubaisha(Moody Girl)
  CS304 GDB Solution Rubaisha(Moody Girl) 0 799 08-10-2016, 01:05 PM
Last Post: Rubaisha(Moody Girl)
  CS304 GDB Admin 0 967 08-04-2016, 02:10 PM
Last Post: Admin
  CS304 assignment #3 2nd solution Rubaisha(Moody Girl) 0 594 07-30-2016, 07:47 PM
Last Post: Rubaisha(Moody Girl)
  CS304 Assignment #3 solution Rubaisha(Moody Girl) 4 1,578 07-30-2016, 12:35 PM
Last Post: Rubaisha(Moody Girl)



Users browsing this thread:
1 Guest(s)