Re: Circles and ellipses
Date: Sun, 26 Aug 2001 14:23:21 -0400
Message-ID: <ogbi7.329$lR.88525936_at_radon.golden.net>
>RM> This is the essential problem that the LSP (Liskov Substitution
>RM> Principle) tries to resolve; or at least identify.
>
>>If one treats values and variables as the same thing, then LSP
>>guarantees that no inheritance is valid unless every subtype is a
>>superset of the values of the supertype, but we already know that a
>>subtype is a subset of the values of the supertype. This would require
>>equivalent sets of values for all types related in any way through
>>inheritance.
>
>Person = { name : string, age : 0-100 } ;
>
>Employee : Person
>{
> salary: 0..N, payroll-id : string
>}
>
>
>Employee is a subtype of Person.
>Employee properties are *not* a subset (not a proper one anyway) of
>the supertype.
I never claimed that the *properties* of a subtype are a subset of the *properties* of the supertype -- I claimed that the *values* of the subtype are a subset of the *values* of the supertype. If you read Date's article, you will see that a subtype is a subset of the values and a superset of the properties.
Returning to your example: Every allowable Employee value in your example is a Person value which makes the allowable values for Employee variables a subset of the allowable values for Person variables.
{
Person oPers;
oPers = Employee("Jill",25,12,"Hourly"); }
The Employee value above is a valid value for the Person variable. Of course, the opposite is not true:
{
Employee oEE;
oEE = Person("Bob",36);
}
How does LSP ever allow inheritance if assignment prohibits substitution? Received on Sun Aug 26 2001 - 20:23:21 CEST