The Rectangle-Square Problem: What It Teaches Us About Liskov Substitution Principle (LSP)

TL;DR LSP means you can use subtype objects anywhere you use base type objects without breaking code. Square/Rectangle inheritance that breaks existing code? That’s a classic LSP problem. Watch for subclasses that throw unexpected exceptions or silently change behavior. When behaviors are too different, reach for composition instead of inheritance. Make interfaces that clearly show what objects can and can’t do to avoid surprises. LSP violations often sneak past unit tests and show up as runtime bugs. The Liskov Substitution Principle isn’t just academic theory - it helps you avoid those “it worked yesterday” bugs that show up in production. When a subclass doesn’t behave like its parent promises, your code breaks in ways that unit tests often miss. ...

July 14, 2025 · Last modified: July 16, 2025 · 12 min · 2251 words · Abhinaw
Diagram showing the five SOLID principles in object-oriented programming

SOLID Principles in C#: A Practical Guide with Real-World Examples

TL;DR - SOLID principles SRP: one class, one reason to change OCP: extend without modifying LSP: subclasses must behave like base types ISP: keep interfaces focused DIP: depend on abstractions, not implementations Introduction This SOLID tutorial in C# walks through each principle: SRP, OCP, LSP, ISP, and DIP, with practical code, refactoring examples, and real-world scenarios. If you’ve been coding for a while, you’ve probably heard of SOLID. It’s a set of five design principles that Robert C. Martin (better known as “Uncle Bob”) came up with back in the early 2000s. Since then, these ideas have become pretty much essential knowledge for anyone writing object-oriented code. ...

June 20, 2025 · Last modified: July 16, 2025 · 21 min · 4162 words · Abhinaw