comp.lang.ada
 help / color / mirror / Atom feed
From: Jon S Anthony <jsa@synquiry.com>
Subject: Re: OOP & Packages in Ada
Date: 1998/02/02
Date: 1998-02-02T00:00:00+00:00	[thread overview]
Message-ID: <uf90rt381v.fsf@synquiry.com> (raw)
In-Reply-To: 6b1atp$ngp$1@Masala.CC.UH.EDU


wanker@exploited.barmy.army writes:

> Now, in this case we want the Eat, Sleep, and Breed methods
> to appear to be part of the Dogs package, because otherwise
> the users of our package would have to know our inheritance
> hierarchy, and also what methods are over-ridden and
> what aren't.  That's too much to have the user worry about,
> and to me seems to hurt the abstraction.

Yes, but that is a well known problem with class based OO stuff.


> I mean to the user, A dog can eat, sleep, and breed as well
> as bark, so it makes perfect sense to have these guys as
> part of the dog package.

They _are_ part of the dog package.  It's just that they are
_implicitly_ declared.  Of course that implies from a documentation
point of view this doesn't help you much (at all...)


> I guess it's debatable as to whether or not it's desirable
> to have people know that a Dog is derived from Mammal, but
> I don't feel it necessary.  Furthermore, the situation gets

Well that's easy enough to fix if you want.  You can make the Dog type
private and then derive if in the private part of the package.  You
then define all the methods you want on Dog in the public part and
indicate they are implemented as the parent Mammal versions in the
private part or the body.  This gives you what you want, but at a cost
of not being able to "conveniently" extend the type later.  Note: all
the polymorphic stuff will still work just fine, you just won't see it
in the clients.


> Object (Appearance)
>    Organism (Reproduction)
>       Animal (Locomotion)
>          Mammal (Fur_Thickness)
>             Dog (Bark)
>               Collie (Grooming)
> 
> 
> Where Object has a method Appearance, and Organism is derived
> from object and it has a method Reproduction, and Animal is derived
> from Organism, etc...
> 
> Now, if we want to work on a Collie type, and wish to
> find out its appearance, reproduction mechanism, locomotion,
> fur thickness, bark, and grooming then we'd have to have
> a knowledge of a 6 leveled inheritance chain

Yes, but that's just standard class based OO.


> and call
> functions with 6 different namespaces qualifiers.

But, no, you can simply use the appropriate most specific one you
want.


> with Objects, Organisms, Animals, Mammals, Dogs, Collies;
> for instance:
> 	Rover : Collies.Collie;
> 
> 
> Objects.Appearance (Rover);
> Organisms.Reproduction (Rover);
> ...
> Collies.Grooming (Rover);
> 
> We can see that this is getting out of hand.  If however the
> Collies package managed to make all the methods seem as a part
> of it, then one simply does:

It does.  Read 3.4 carefully.  In particular (17).  For example,

package Animals is

    type Animal is tagged null record;

function Appearance (X : Animal ) return String;

end Animals;


package Animals.Organisms is

    type Organism is new Animal with null record;

function Locomotion (X : Organism) return String;
function Reproduction (X : Organism) return String;

end Animals.Organisms;


package Animals.Organisms.Mammals is

    type Mammal is new Organism with null record;

function Fur_Thickness (X: Mammal) return String;

end Animals.Organisms.Mammals;


package Animals.Organisms.Mammals.Dogs is

    type Dog is new Mammal with null record;

function Bark (X : Dog) return String;

end Animals.Organisms.Mammals.Dogs;


package Animals.Organisms.Mammals.Dogs.Collies is

    type Collie is new Dog with null record;

function Grooming (X: Collie) return String;

end Animals.Organisms.Mammals.Dogs.Collies;


with Animals.Organisms.Mammals.Dogs.Collies;
use Animals.Organisms.Mammals.Dogs.Collies;

with Ada.Text_Io;  use Ada.Text_Io;

procedure Test is

    Rover : Collie;

begin
    Put_Line(
        "Rover : " &
        Appearance(Rover) &
        Reproduction(Rover) &
        Locomotion(Rover) &
        Fur_Thickness(Rover) &
        Bark(Rover) &
        Grooming(Rover));
end Test;

$ gnat test.adb
$ ## no problemo...

> Which is a lot simpler, and would be more intuitive -- the user
> would not have to know or care if the methods were over-ridden
> or not.

Well, then, you should be happy.


/Jon

-- 
Jon Anthony
Synquiry Technologies, Ltd., Belmont, MA 02178, 617.484.3383
"Nightmares - Ha!  The way my life's been going lately,
 Who'd notice?"  -- Londo Mollari




  parent reply	other threads:[~1998-02-02  0:00 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-01-30  0:00 OOP & Packages in Ada wanker
1998-01-31  0:00 ` Mats Weber
1998-01-31  0:00   ` Nick Roberts
1998-01-31  0:00 ` Matthew Heaney
1998-02-01  0:00   ` wanker
1998-02-01  0:00     ` Matthew Heaney
1998-02-01  0:00     ` Tom Moran
1998-02-02  0:00     ` Jon S Anthony [this message]
1998-02-02  0:00     ` Anonymous
1998-02-03  0:00     ` John English
1998-02-04  0:00   ` Don Harrison
1998-02-04  0:00     ` Matthew Heaney
1998-02-05  0:00       ` Don Harrison
1998-02-06  0:00         ` Bob Collins
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox