NOTE

Liskov Substitution Principle

What the Liskov substitution principle is, why it is needed, and how subclasses should preserve the meaning of parent-class behavior.

Software Architecture & EngineeringCreated Updated 1 min readhistorical

This is a historical learning note and may contain outdated or incomplete understanding.

1. What Is the Liskov Substitution Principle?

Do not break the inheritance hierarchy. When a subclass overrides a method and changes its behavior, it should not affect the meaning of the parent-class method.

It is the embodiment of the open–closed principle in inheritance.

2. Why Is the Liskov Substitution Principle Needed?

Improve software reusability through inheritance.

3. Implementing the Liskov Substitution Principle

A subclass can implement abstract methods of the parent class, but should not override non-abstract methods of the parent class.

A subclass can add methods specific to itself.

4. References

Discussion

Sign in with GitHub to comment. Discussions are stored as GitHub Issues.View on GitHub