The Problems with Inheritance
Reading
-
Item 18: Favor Composition Over Inheritance
Bloch, Joshua. Effective Java. 3rd ed., Addison-Wesley Professional, 2017.
Important concepts
- errors introduced by overriding methods
- composition
- forwarding
- wrapper class
Things to consider (exercises for yourself, not to turn in)
- What does it mean for a class B to be a subtype of class A? What are some strategies you can imagine to determine whether every instance of B is really an A?
- What happens when you override a method inherited from a superclass? Could you trace a series of method calls made be a subclass B which inherits from and overrides methods in superclass A?
Your response
What was particularly interesting, confusing, or exciting to you in this reading?