shlogg · Early preview
Prashant Mishra @prashantrmishra

Breaking Inheritance Hierarchy With Liskov Substitution Principle

Objects should be replaceable with their subtype without affecting code correctness. Inheritance can lead to substitution failures, breaking hierarchy or using "Tell don't ask" principle can solve this issue.

Objects should be replaceable with their subtype without affecting the correctness of the code

Let's understand this with inheritance(Is-a relationship)
example: Ostrich is a bird, Hunchback is a car, etc.
Example: Racing-car is a car

public class Car{
    public double getCabinWidth(){
        //return cabin width
    }
}

    
    

    
    





public class RacingCar extends Car{
    @Override
    public double getCabinWidth(){
        //UNIMPLEMENTED
    }
    public double getCockpitWidth(){
        //return the cockpit width of the racing car
    }
}

    
    

    
    




RacingC...