LSP (was Re: Function.prototype.bind)

waldemar at waldemar at
Wed Sep 24 14:08:32 PDT 2008

> Waldemar Horwat wrote:
>> Graydon Hoare wrote:
>>> Quoting Liskov[1]:
>>>    "What is wanted here is something like the following substitution
>>>     property: If for each object o1 of type S there is an object o2 of
>>>     type T such that for all programs P defined in terms of T, the
>>>     behavior of P is unchanged when o1 is substituted for o2, then S
>>>     is a subtype of T."
>>> Think it over. Imagine what you'd have to delete from any language you
>>> use, for its "subtype" relation to conform to that definition.
>> What?  For example, what would you have to delete from Java, ignoring
>> the parts where a program can examine itself like reflection?
> The big one is "method overriding in subtypes", though as you say there
> are various other cases such as reflection. If I have a program that
> uses some type:
>    class Mul {
>      int f(int x, int y) { return x * y; }
>    }
> I can form a subtype such that substituting the subtype for the
> supertype in some program will likely change the behavior of the program:
>    class NotTheMulYoureLookingFor extends Mul {
>      int f(int x, int y) { return x + y; }
>    }

What does this have to do with your claim about the Liskov property? 
Where in this example do you take an object o1 of type
NotTheMulYoureLookingFor and prove that there is no object o2 of type Mul
that satisfies the Liskov property?


More information about the Es-discuss mailing list