Re: Clean Object Class Design -- What is it?
Date: Sat, 21 Jul 2001 23:34:31 GMT
Message-ID: <yVH17.10886$Kf3.118667_at_www.newsranger.com>
In article <fYy17.665$G42.294_at_newsfeed.slurp.net>, Rico says...
>Here's the abstract version, substitute whatever
>worthy real-world objects you'd like in there:
>
>abstract class A
>{
> domainType1 x;
> // operations follow
>}
>
>class B extends A
>{
> ...
> domainType2 y;
> // operations follow
>}
>
>class C extends A
>{
> domainType3 z;
> // operations follow
>}
>
>A very typical object-oriented programming pattern would be to have a
>container containing objects of type B and C. We could iterate across that
>container setting attribute x to values, without concern as to whether we
>are dealing with an object of type B or type C.
>
>How do we accomplish the same function using the relational model? Well, we
>can flatten the hierarchies (assume we find a primary key somewhere in the
>objects, another complication of using relations with an OO model):
>
>B(...,domainType1 x, domainType2 y), C(...,domainType1 x, domainType3 y)
>
>Now the update on that container means asking the object "what kind of thing
>are you?" and then executing one of two kinds of update statements based on
>the response.
The first problem is that some x might answer "both".
Answering your question literally:
select AB.x x, "B" type from AB
union
select AC.x x, "C" type from AC
(I found nore intuitive to rename your tables to AB and AC)
You need to be more specific about what you want to do polymorphically in order to get more reasonable answer how would we translate it into relational. There is no such thing as abstract problem modelling in the relational, we need a concrete schema to start with.
>The final option, and the one you mention in your response, is to put all
>attributes of every class in the inheritance tree into a single relation.
>An additional field can then indicate what kind of object it is. Problem
>with this is obvious: you'll waste a lot of space if you have a
>moderately-sized application. A lot of your fields will be empty because
>you'll only use a subset of them at any given time.
>
Make it a view
select AB.x, AB.y, AC.z from AB, AC where AB.x=AC.x
then, what's the problem? Received on Sun Jul 22 2001 - 01:34:31 CEST
