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

Re: OO should break when broken




On Wednesday, September 3, 2003, at 05:15  PM, Colin Putney wrote:
>>>> Stated in another way, the essense of a subclass is to constrain the
>>>> set of states of the superclass.
>>>
>>> Interesting. Would you care to give an example, or explain why you
>>> believe this?
>>
>> If you reread my previous post, you will find that it talks about the 
>> set
>> of states that objects of the superclass and the subclass may take 
>> (please
>> take some time to understand it). The discussion about the states is 
>> a big
>> part of the reason why I think that the above characterization is
>> basically accurate.
>
> Actually I did read your previous post quite carefully. You made a 
> very formal assertion. I congratulate you the precision with which you 
> described it. What I don't understand us why you believe it to be > true.
>
>> It is hard to not come with an example. In fact, I find it more 
>> difficult
>> to find meaningful subclasses that are not constraining their 
>> superclasses
>> in any way.
>>
>> A simple example would be a LinkedList[WithSlowSize] class that does 
>> not
>> cache the size (or length or number of nodes in the list) of the list 
>> and
>> a subclass LinkedListWithFastSize that would cache the size of the 
>> list in
>> additional state. It is very easy to see that in 
>> LinkedListWithFastSize,
>> the set of valid states of the superclass portion (the linked list 
>> head)
>> and the set of valid states of the added state (the size or the 
>> number of
>> nodes in the linked list) are strongly dependent (specifically, for a
>> specific length, only lists that contain exactly that many nodes are 
>> valid
>> and for a specific list only a single length is valid) and that the 
>> set of
>> valid states is a small proper subset of the cartesian product of the
>> independent parts of the valid state.
>
> 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?

john clements