Introduction to OOP
Chapter 14: Polymorphism and Software Reuse:
next
previous
audio
real
text
Advantages and Disadvantages of Each Mechanism
Composition is simpler, and clearly indicates what operations are provided.
Inheritance makes for shorter code, possibly increased functionality, but makes it more difficult to understand what behavior is being provided.
Inheritance may open to the door for unintended usage, by means of unintended inheritance of behavior.
Easier to change underlying details using composition (i.e., change the data representation).
Inheritance may permit polymorphism
Understandability is a toss-up, each has different complexity issues (size versus inheritance tree depth)
Very small execution time advantage for inheritance
Intro OOP,
Chapter 14
, Slide 08