Re: Liskov Substitution Principle and Abstract Factories

From: Dmitry A. Kazakov (mailbox_at_dmitry-kazakov.de)
Date: 01/25/05


Date: Tue, 25 Jan 2005 14:01:37 +0100

On Wed, 19 Jan 2005 02:57:38 +0800, smilemac wrote:

> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message
> news:1jwxyc32xmolk.1s0jv7gb1tslb$.dlg@40tude.net...
>> On Wed, 19 Jan 2005 01:13:27 +0800, smilemac wrote:
>>
>>>> The problem though is that:
>>>>
>>>> 1. out-parameters are needed too often to be ignored. Consider Integer::++
>>>> which is an inout-method, and Positive is still substitutable there
>>>> (differently to Integer::--).
>>>
>>> I don't think so. You just need re-declare the operator ++ in Positive
>>> definition and redirect the call to the base class, Integer. It's just a
>>> very low cost.
>>
>> But I can safely inherit it. This is just an example. There could be a very
>> complex thing very difficult to judge about. The idea of LSP was to get the
>> result for free. But there is no free cheese, outside, you know where ...
>>
>>>> 2. in-parameters also violate LSP in subtyping by generalization. Consider
>>>> Complex and Real. Complex is not an in-subtype of Real (it is an
>>>> out-subtype, though.) Also so beloved type extension violates LSP.
>>>
>>> For a generic Complex and generic Real, your are right. Complex is not a
>>> subtype of real. In fact, type in computer science never equals to the
>>> similar concept in math. It depends on your detailed contracts residing in
>>> your concrete implementations.
>>
>> Actually A is a LSP-subtype of B = all theorems valid for the domain set of
>> B are true for the domain set of A. It is plain wrong. Mathematically it is
>> a nonsense. The circle-ellipse problem is unsolvable because of the
>> following theorem:
>>
>> forall X,Y of Real, exists Z of Ellipse such that X-axis of Z=X and Y-axis
>> of Z=Y.
>>
>> This theorem is required to implement mutable Resize. But it is trivially
>> wrong when Ellipse is replaced by Circle:
>>
>> forall X,Y of Real exists Z of Circle such that X-axis of Z=X and Y-axis of
>> Z=Y.
>>
>> This is as simple as tooth-powder! (:-))

> That problem is well known, but also have been proven that it is not a real
> problem for LSP.

Which proof you are talking about?

> The reason like I said just before, the type meaning here
> is not that one in math or other subjects.

Do you mean that mathematics and logic are inapplicable for software
construction. Is that your point?

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de