Grokking SOLID Design Principles
Vote
0% completed
The Rules a Subclass Must Follow
Every violation you have seen so far in this chapter announced itself. The subclass threw an exception, the program stopped, and the problem was easy to find.
Those are the easy ones. The dangerous violations return a wrong answer and let the program carry on.
This lesson gives the full contract a subclass has to keep. There are four rules, and throwing an exception breaks only one of them.
A Violation That Never Throws
A square is a rectangle. Every school textbook says so, and the inheritance looks obvious.
Square inherits from Rectangle
.....
.....
.....
Like the course? Get enrolled and start learning!
Reading Progress
0%