CSC/ECE 517 Fall 2007/wiki1 7 c9: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
Line 1: Line 1:
= Concept to explore =
== Concept to explore ==


''Multiple inheritance is a controversial concept. Detractors say it leads to messy class hierarchies, it is impossible to implement efficiently, and when the same method is inherited along two different paths, there is no good way to decide automatically which definition should be used. Do mixins solve all of these problems? Give (or cite) examples (e.g., Java, C++, and/or Ruby) to illustrate your conclusions. Are mixins a clear advance over interfaces? Do mixins have any disadvantages not shared by multiple inheritance or interfaces?''
''Multiple inheritance is a controversial concept. Detractors say it leads to messy class hierarchies, it is impossible to implement efficiently, and when the same method is inherited along two different paths, there is no good way to decide automatically which definition should be used. Do mixins solve all of these problems? Give (or cite) examples (e.g., Java, C++, and/or Ruby) to illustrate your conclusions. Are mixins a clear advance over interfaces? Do mixins have any disadvantages not shared by multiple inheritance or interfaces?''
== Real World Problem ==
Let us take a real world example and see why some sort of multiple inheritance is required. Then see in phases how each language C++, Java, Ruby deals this problem.
Consider a part-time student this means that he is both a student as well as an employee(typically). But in first place he is a also person. So, he will have attributes and functions of both a student and also of an employee. Since these two classifications first belong to the classification person, part-time student also gets any attributes from the person as well. Lets consider some essential features of a person he eats, he will have fun and also say he has some attribute i to say about his state. The fun a student will have will be different from an employee, so we should distinguish that and the state. Now the fun a part time student(if any!) might change. So now comes the problem, from where should we derive the fun for part-time student?
[[Image:ExampleClass.jpg]]


== References: ==
== References: ==

Revision as of 03:41, 14 September 2007

Concept to explore

Multiple inheritance is a controversial concept. Detractors say it leads to messy class hierarchies, it is impossible to implement efficiently, and when the same method is inherited along two different paths, there is no good way to decide automatically which definition should be used. Do mixins solve all of these problems? Give (or cite) examples (e.g., Java, C++, and/or Ruby) to illustrate your conclusions. Are mixins a clear advance over interfaces? Do mixins have any disadvantages not shared by multiple inheritance or interfaces?

Real World Problem

Let us take a real world example and see why some sort of multiple inheritance is required. Then see in phases how each language C++, Java, Ruby deals this problem. Consider a part-time student this means that he is both a student as well as an employee(typically). But in first place he is a also person. So, he will have attributes and functions of both a student and also of an employee. Since these two classifications first belong to the classification person, part-time student also gets any attributes from the person as well. Lets consider some essential features of a person he eats, he will have fun and also say he has some attribute i to say about his state. The fun a student will have will be different from an employee, so we should distinguish that and the state. Now the fun a part time student(if any!) might change. So now comes the problem, from where should we derive the fun for part-time student?

File:ExampleClass.jpg

References:

  1. Programming Ruby: The programmatic programmer’s guide
  2. Deadly diamond of death by Robert Martin
  3. A very insightful article from thoughtbot
  4. Wiki entry on Ruby
  5. The C++ code snipped has been adapted from this site


See Also

  1. A very insightful article from O'reilly
  2. One more blog on mixins, modules and inheritence