Liskov Substitution Principle

A child class must work anywhere its parent class is expected, without surprises.

What is Liskov Substitution Principle?

The Liskov Substitution Principle says a child class must work anywhere its parent is expected, without surprises. If code works with a Bird, it must still work when handed any kind of bird.

// Breaks the rule: code that calls bird.Fly() crashes for penguins
public class Penguin : Bird
{
    public override void Fly() => throw new NotSupportedException();
}

Level: Freelancer · More OOP terms at this level

Updated