[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: OO should break when broken




On Thursday, September 4, 2003, at 01:30  PM, Colin Putney wrote:

>
> On Thursday, September 4, 2003, at 06:28  AM, John Clements wrote:
>
>>> Yes, what you say is true. But I don't see how you could 
>>> characterize this as the subclass constraining the superclass. For 
>>> every valid LinkedList, there is a valid LinkedListWithFastSize.
>>
>> Not if you consider elements of other possible subclasses of 
>> LinkedList as 'valid LinkedLists', which by subtyping they ought to 
>> be.  For instance, imagine a LinkedList subclass 
>> LinkedListWithTimeStamp, which tracks when it was created.  Would you 
>> claim that for each element of this subclass, there is a unique 
>> LinkedListWithFastSize?
>
> No. Obviously there isn't. Let me rephrase my claim: "For every valid 
> instance of LinkedList, there is at least one valid instance of 
> LinkedListWithFastSize." The same holds true for 
> LinkedListWithTimeStamp: "For every valid instance of LinkedList, 
> there is at least one valid instance of LinkedListWithTimeStamp." Was 
> your objection to my loose usage of 'valid LinkedList,' or to my 
> broader position on subclassing?
>
> The point is that the full range of state that is valid in the 
> superclass is also valid in the subclass. It isn't restricted, which 
> Vesa claimed was "the essence of a subclass."

No, I disagree.  It _is_ restricted.  How is it restricted?  It is 
restricted because it _must_ contain the extra state.  So, for 
instance, the LinkedListWithTimeStamp restricts the LinkedList by 
requiring the presence of the TimeStamp state.  Likewise, the 
LinkedListWithFastSize restricts the LinkedList by requiring the 
presence of the cached size state.

I think the key point is that the set of "LinkedLists" doesn't just 
include direct instances of LinkedList; it also includes instances of 
any possible subclass thereof.

***

Here's my argument:

1. if B is a subclass of A, then A is the more general one.  Always.


john clements