Part 1 of 6 · 1 min read
Why this page comes third
In this module you will
- State the Liskov substitution principle (LSP) in plain words.
- Explain why a square is not a safe subclass of a rectangle.
- Spot a subclass that breaks the promises of its parent.
- Rewrite such a design so that callers need no type checks.
- Name warning signs: type checks, "not supported" exceptions and special cases.
Modules 3 and 4 of Level 1 showed interfaces and inheritance. This page gives the test for when inheritance is safe. The sources are "Clean Architecture" (CA), chapter 9, and "Effective Java" (EJ), Item 10. The rules in section 4 are common practice and are labelled so. Code was compiled and run before it was written here. Numbers marked "made up" only show the idea.