Java-Liskov Substitution Principle

Liskov Substitution Principle

It formally states that

-the preconditions of a subclass’s behaviour (methods) cannot be strengthened, meaning (among other things) that a sub-method cannot accept a narrower range of inputs than the original method.

-The post conditions of a sub-method cannot be weakened, meaning that the sub-method cannot have a broader range of effect than the original method.

在这里插入图片描述

WEAKER ==== WIDER; STRONGER ==== NARROWER.

For the LSP to be preserved, the sub-method should be smiling! (we don’t care about the super method, because it is what it is)

猜你喜欢

转载自blog.csdn.net/Nick_kn/article/details/109584092