Re: domains aren't subtypes, right?
Date: Fri, 23 May 2003 12:08:58 +0000
Message-ID: <2915060.1053691738_at_dbforums.com>
Originally posted by Kieran
> Marshall Spight wrote:
>
> > Hi,
> >
> > So, I sometimes hear this idea that you could create a new type
> from
> > an existing type. One example I've heard is that you could
> declare
> > a "city" type (as part of an address) that was in some way
> derived
> > from the string type. Then you could decide what
> operators/functions
> > this new type would "get" (inherit?) from its originating type.
> For example,
> > you might want to compare city values for equality, or for
> lexical order,
> > but you wouldn't meaningfully want to concatenate city values,
> even
> > though city comes from string and string has a concat
> operator.
> >
> > Sometimes I hear this called a "domain" but that word seems
> heavily
> > overloaded.
>
> Domain and type are generally taken to be synonyms - I guess
> relational
> theory tends to use domain for historic reasons.
>
>
> > So what is the relationship of the city type to the string type?
>
> > It's not a subtype.
>
> I agree, since a subtype must have all the properties that it's
> supertype has.
>
> > Could it be a supertype?
>
> Yes and no.
>
> If type CITY is a supertype of type STRING then STRING is a subtype of
> CITY by definition.
> If STRING is a subtype of CITY then all strings are cities by
> definition.
> But saying that all strings are cities doesn't really sound right.
>
> It might be better to have a type called BASIC_STRING that
> doesn't have
> concatenation as the root string type, and make the STRING type a
> subtype of BASIC_STRING. You could then declare your address attribute
> as having type BASIC_STRING, or have CITY as a synonym (or possibly
> subtype) of BASIC_STRING.
>
> > Some other kind of relationship entirely?
>
> In OO terminology one might say that CITY delegates to STRING.
>
> Regards,
> Kieran Elby
Type CITY is neither a supertype nor a subtype of STRING, it is a type
that is represented using a STRING.
Suppose instead of CITY it had been POSTCODE. In the UK, a POSTCODE is analogous to the US ZIPCODE, but it has two parts, the "outer" and the "inner" code, e.g. "AB12 3CD." Now if we decided to represent POSTCODE using a single STRING we would be in the same position as with CITY.
But suppose instead we decide instead to represent POSTCODE as 2 STRING values like this:
Type POSTCODE is (Outer STRING, Inner STRING )
Now it is obvious that POSTCODE is not a subtype of STRING, because it is made up of 2 STRING values. It is also clear that it cannot inherit operators from STRING, the operators need to be defined explicitly. For example, "less than" could be defined in 2 different ways (at least):
- p1 < p2: (p1.outer < p1.outer OR (p1.outer = p2.outer AND p1.inner < p2.inner)
e.g. POSTCODE('AB12','3CD') < POSTCODE('CD12','1AB')
2) p1 < p2: (p1.inner < p1.inner OR (p1.inner = p2.inner AND p1.outer
< p2.outer)
e.g. POSTCODE('CD12','1AB') < POSTCODE('AB12','3CD')
It is also obvious that POSTCODE is not a supertype of STRING, because STRING is not a subtype of POSTCODE (since POSTCODE is defined in terms of 2 STRINGs!)
-- Posted via http://dbforums.comReceived on Fri May 23 2003 - 14:08:58 CEST