In the previous post, we covered:
SRP (keep classes focused)
OCP (extend without modifying)
Those help you structure code well.
But even with those applied, systems can still break in subtle ways:
inheritance behaving unexpectedly
classes forced to implement irrelevant methods
tight coupling making changes painful
That’s where the remaining SOLID principles come in:
LSP (Liskov Substitution Principle)
ISP (Interface Segregation Principle)
DIP (Dependency Inversion Principle)
LSP — Liskov Substitution Principle
Subclasses should be replaceable for their base classes without breaking behavior.
The classic mistake
Bird: - fly()
Penguin extends Bird: - fly() → throws error
Enter fullscreen mode
Exit fullscreen mode
This design assumes:
All birds can fly
But penguins cannot.
Now, anywhere Bird is used, substituting it with Penguin breaks the system.
What actually went wrong
The issue is not inheritance.
The issue is:
The base class was designed incorrectly.
Correct approach
Bird: -…