The Problems with Inheritance
Reading
- Read The Problems with Inheritance. This is a long reading, so give yourself time to take breaks or read it in multiple sittings.
- Optional, if you want to go deeper: Read Item 18: Favor Composition Over Inheritance (Bloch, Joshua. Effective Java. 3rd ed., Addison-Wesley Professional, 2017.) The entire book is excellent, and the Macalester library has it!
Important concepts
- composition
- Liskov Substitution Principle
- customization by subclassing
- breaking encapsulation
And if you read the optional Effective Java reading:
- 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?