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.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of inheritance

inheritance

Photo of real meaning

real meaning

Photo of liskov substitution

liskov substitution

Related news:

News photo

How can you represent inheritance in a database? (2010)

News photo

If Inheritance is so bad, why does everyone use it?

News photo

She spent her inheritance sending money to TikTok Livestreamers. What started as a game turned into addiction.