Re: Clean Object Class Design -- Circle/Ellipse

From: Mikito Harakiri <nospam_at_newsranger.com>
Date: Tue, 07 Aug 2001 16:34:11 GMT
Message-ID: <7MUb7.1661$NJ6.5968_at_www.newsranger.com>


In article <9koatn$6q$1_at_news.tue.nl>, Jan Hidders says...
>
>Mikito Harakiri wrote:
>>
>> I would suggest I[Real,Integer] mapping any real r into integer i as
>> follows:
>>
>> i = floor(r)
>
>That would be the wrong way around because then you would try to make
>the Reals a subtype of Integer.

Yes it looks odd, at first, because my conclusion is that model A is a sybtype of the model B when B's universe is a subset of A's one! Yet again, our primary concern here is substutability, not set inclusion. Being able to substitute a model means that B must have
1. operations with the same signature as A 2. semantics of operations on B must be "consistent" with that of A

>> > 2. The second is that the semantics of the functions should respect the
>> > subtype ordering and this interpretation function. This means that
>> > if you have two function f_i : D_i -> C_i and f_j : D_j -> C_j with
>> > the same name and a greatest common subtype D' exists of D_i and D_j
>> > and a greatest common supertype C' of C_i and C_j exists, then if we
>> > interpreat f_i and f_j as functions from D' to C' then they must be
>> > the same, i.e., for all x in D' it holds that
>> >
>> > I[C_i,C']( f_i( I[D',D_i](x) ) ) = I[C_j,C']( f_j( I[D',D_j](x) ) )
>> >
>> > So if you tell me what operations you have over the integers and the
>> > reals, and what your subtype interpreations is, then I can tell you if
>> > a subtyping relation between them is valid.
>>
>> Again, couldn't this condition be formulated in terms of super- and
>> subclass only?
>
>No. You have to make a statement about the semantics that says
>something like "if I have an expression with operators and constants
>then the meaning of this expression does not depend upon what sub- or
>supertypes I assign to them". Since this is a semantical expression you
>have to say something about the semantics and/or the axioms that define
>your functions.
>
>It looks a lot more difficult then it really is. Suppose you have the
>integer plus (I+) and the real plus (R+), and the (in some sense)
>trivial mapping I[Int,Real] : Int -> Real, then it says that 1 + 1
>has always the same meaning, i.e., the result is the same if I first
>convert the 1's to 1.0's and then use R+ or if I immediately apply I+
>and convert the result to a Real. In formulas:
>
> I[Int,Real](1) R+ I[Int,Real](1) = I[Int,Real](1 I+ 1)

Here you did exactly what I asked. Just add a disclamer: "where '+' is any operation, and 'Int', 'Real' are 2 arbitrary domains". It requires some reader's imagination to extend it to n-ary operations, but it's cheap generalization, anyway.

>> > For starters lets assume for the Reals (R,+,*) and for the Integers
>> > (I,+,*). So we have the domains R and I and the operators + : R x R ->
>> > R, * : R x R -> R, + : I x I -> I and + : I x I -> I. And because I
>> > have to get back to work now, checking that we can indeed regard the
>> > integers as a subtype of the reals is left as an exercise for the
>> > reader. :-)
>>
>> With "I" being i = floor(r), couldn't reals be a subclass of integers?
>
>Well, let's see, it should hold for all Reals x, y that,
>
> floor(x) I+ floor(y) = floor(x R+ y)
>
>Yes, it holds, so they could, if this is your only operator. :-)

You mean '+' is my only operator? I see that I can't make it

floor(x) I* floor(y) <==> floor(x R* y)

>But.... usually you also have an equality operator R= : R x R -> Bool
>and I= : I x I -> Bool and then it should also hold that,
>
> (floor(x) I= floor(y)) = (x R= y)
>
>and that doesn't hold. So if you have equality operators (and you
>almost always have) then the interpretation function I[SubDom,SupDom] L
>SubDom -> SupDom must be injective.

Couldn't the condition be relaxed to just

(floor(x) I= floor(y)) <== (x R= y)

? Anyway, I see that I need to repair multiplication consistency at least... Received on Tue Aug 07 2001 - 18:34:11 CEST

Original text of this message