Get the latest tech news
Liskov Substitution: The real meaning of inheritance
Part 3 of our Clean Architecture series, exploring the 'L' in SOLID
Inheritance isn’t always the answer- prefer composition when behavior differs Think in terms of contracts- subtypes must fulfill the base type’s contract Use contract tests to verify LSP compliance Document pre/postconditions clearly Return types matter- be consistent with null/non-null, exceptions, etc. Stay tuned for our next post in the series, where we’ll explore the Open-Closed Principle! Pro tip: If you find yourself writing comments like “don’t use X in Y way” or “this override behaves differently”, you might be violating LSP.
Or read this on Hacker News