Newsgroups: comp.object
From: ggro...@bigfoot.com (S Perryman)
Date: 9 Dec 2003 03:27:26 -0800
Local: Tues, Dec 9 2003 6:27 am
Subject: The works of Liskov and Wing [LONG] (Was: Class hierarchy design question)
Ryan Kinderman <r...@kinderman.net> wrote in message <news:3fd418eb$1_2@newspeer2.tds.net>... 1. There is a boolean predicate : substitutable-for(T2,T1,C) >Actually, the Liskov Substitution Principle says that "*Functions* >that use pointers or references to base classes must be able to use >objects of derived classes without knowing it." >It seems to me that, by this definition, the only requirement is that >if you have a function that takes, as an argument, an instance of >FruitList, the function should only operate on generic FruitList >instances, and not be concerned with the specific type of fruit >contained therein. I'm assuming that AppleList and OrangeList exist >because there is a need for some strongly-typed FruitList >functionality. Perhaps, for instance, the FruitList class has an >Item(int index) operation that returns a Fruit object, but does not >implement an Add() operation. The strongly-typed AppleList class >implements Add(anApple), to force a client to add the correct type of >Fruit (the same would be true for OrangeList). >In the case I've described, perhaps a function exists that does not >need to add fruits to the list, but simply access them for some >purpose, without concern for the specific kind of fruit. To that end, >the function takes as an argument a FruitList class. With my >understanding of the Liskov principle, it seems that a violation >would only occur if that function had to cast the list argument to >a specific kind of FruitList, as this would mean that the function >had to know which kind of FruitList was passed in as an argument. >Is this a correct understanding of the principle, or am I missing >something? that is true if in a (program) context C, an instance of type T2 2. A definition of this predicate for *OO* was given by Simula many substitutable-for(T2,T1,C) = inheritance-lineage(T2,T1) If T2 (directly or indirectly) inherits properties from T1, then T2 3. Liskov and Wing effectively define the predicate thus : substitutable-for(T2,T1,C) = - T2 always satisfies the type invariant of T1. - For any operation OP invoked on T1 in C, T2::OP : -- Satisfies the preconditions for itself or those of T1::OP. 4. Liskov and Wing then move to their definition of a *subtype* , LW-Subtype(T2,T1) = What this all means is that this term "Liskov Substitution Principle" They tell us what they want type substitutability to mean. So for your example : AppleList/OrangeList are substitutable for FruitList. In fact, As you have correctly noted, adding any fruit to an AppleList/ What people who actually understand the work of Liskov/Wing know, is - Type substitutability is a more universal concept than OO inheritance. - OO provides weaker type substitutability than desired by Liskov and - Type substitutability conflicts have nothing to do with inheritance. - The organisation of programs into a set of Liskov/Wing subtypes, Regards, You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||
