SUBTYPES MUST BE SUBSTITUTABLE FOR THEIR BASE TYPES.

하위타입의 객체가 상위 객체를 대체할 수 있어야 한다.

Have you ever seen code that has lots of instanceof expressions in the clauses of if
statements. Though there are some legitimate uses for expressions like this, they are few
and far between. Usually they are a result of violating the LSP, and are themselves a violation
of the OCP.

The LSP says that the users of base classes should not have to do anything special in
order to use derivatives. Specifically, they should not have to use instanceof, or downcasts.
Indeed, they should know nothing about the derivatives at all. Not even that they
exist.

Consider the payroll application shown in Figure 6-8. The Employee class is abstract
and has an abstract method named calcPay. It’s pretty clear that SalariedEmployee
will implement this to return the employee’s salary. It’s also pretty clear that Hourly-
Employee will implement it to return the hourly rate times the sum of the hours on this
week’s time cards.

+ Recent posts