The Liskov Substitution Principle does more than you think

This title could be clearer and more informative.Try out Clickbait Shieldfor free (5 uses left this month).

The Liskov Substitution Principle (LSP) is commonly understood as just the 'L' in SOLID, applying only to inheritance hierarchies. But the original Liskov-Wing paper's core insight — that subtypes must have weaker or equal preconditions and stronger or equal postconditions — applies far more broadly. Any time you substitute one function or code block for another (including API versioning and backward compatibility), the same contract rules apply. Making a required parameter optional weakens preconditions (safe), while making an optional parameter required strengthens them (breaking). The post also connects this to Hyrum's Law: any observable behavior can become an implicit postcondition that someone depends on, meaning even 'strengthening' a postcondition by adding new output fields can break callers who relied on the absence of those fields.

7m read timeFrom buttondown.com
Post cover image
2 Impressions