visit
Example:
❌ Before SRP
➡️ Car handles both driving and tire maintenance.
✅ After applying SRP
➡️ Now, Car focuses on driving, while TireService handles tire maintenance.
Example:
❌ Before OCP
➡️ Vehicle handles gear change for both ManualCar and AutomaticCar.
✅ After OCP
➡️ Now, the Vehicle delegates gear changes to separate Transmission implementations, allowing for easier addition of new transmission types without modifying the Vehicle.
Example:
❌ Before LSP
➡️ Penguin inherits from Bird and overrides the fly method, but penguins can’t fly, causing issues when using Penguin as a Bird.
✅ After applying LSP
➡️ Now, we have a more suitable hierarchy: Bird class provides a generic move method, while FlyingBird and Penguin implement their specific movement behavior, making it safe to use them interchangeably.
Example:
❌ Before ISP
➡️ Vehicle interface contains both drive and fly methods, forcing Car to implement a method it doesn’t need.
✅ After applying ISP
➡️ Now, we have separate Drivable and Flyable interfaces, allowing Car and Airplane to implement only the methods they need, resulting in cleaner and more modular code.
Example:
❌ Before DIP
➡️ Lamp class directly depends on the concrete LightBulb class, making it less flexible.
✅ After applying DIP
➡️ Now, Lamp depends on an abstract Switchable interface, allowing it to work with any Switchable implementation, making the code more flexible and maintainable.
Also published here