From: comar@cs.nyu.edu (Cyrille Comar)
Subject: Re: Ada 90 inheritance request?
Date: 9 Dec 1994 12:26:13 -0500
Date: 1994-12-09T12:26:13-05:00 [thread overview]
Message-ID: <3ca3vl$n14@lang8.cs.nyu.edu> (raw)
In-Reply-To: D06zwx.27r@inmet.camb.inmet.com
stt@spock.camb.inmet.com (Tucker Taft) writes:
:
: Here is the note on multiple inheritance in Ada 9X.
: -Tucker Taft
Thank's Tuck for your very instructive note. I love this kind of post where I
fill like learning something rather than listening to someone complains.
By the way, I have an intersting challenge for our Ada9x experts. Here is a
problem that would have an obvious solution with Multiple Inheritance, I would
like to see how it can be solved cleanly in 9x. The problem is not abstract,
this is something that everybody will need at some point.
PROBLEM: I have defined a hierarchy or tagged types and now I would like
specialize one of them to be controlled (i.e. finalizable)
with MI, I could write something like:
type Ctrl_T is new T, Controlled with null record;
-- overriding of Initialize/Adjust/Finalize
procedure Initialize (Obj : in out Ctrl_T);
procedure Adjust (Obj : in out Ctrl_T);
procedure Finalize (Obj : in out Ctrl_T);
and it would be the end of it...
Beginning of Solution
---------------------
Following your suggestions, we could define a generic package:
generic
type T is tagged private;
package Make_it_Controlled is
type Ctrl_T is new T with private;
procedure Initialize (Obj : in out Ctrl_T);
procedure Adjust (Obj : in out Ctrl_T);
procedure Finalize (Obj : in out Ctrl_T);
private
type T_Controller is new Controlled with null record;
procedure Initialize (Obj : in out T_Controller);
procedure Adjust (Obj : in out T_Controller);
procedure Finalize (Obj : in out T_Controller);
type Ctrl_T is new T with record
Ctrl : T_Controller;
end record;
end;
and then I need to be able to call Initialize on Ctrl_T inside the Initialize
of type T_Controller. Each time a variable V of type Ctrl_T is defined
the Initialize on V.Ctrl will be called and will itself call Initialize on V.
But now I am stuck because there is no way in the body of Initialize on
T_Controller to refer to the englobing object.... Argggg
Tuck gave another nice trick by using access discriminant that solves partially
the problem. We can use it to redefine the controller:
type Acc is access all Ctrl_T;
type T_Controller (Englobing_Obj : Acc) is new Limited_Controlled
with null record;
type Ctrl_T is new T with record
Ctrl : T_Controller (Ctrl_T'Access);
end;
and now I can write Initialize
procedure Initialize (Obj : in out T_Controller) is
begin
Initialize (Obj.Englobing_Obj.all);
end;
And everything would be nice if it was legal... The problem is that the access
discriminant requires a LIMITED TYPE and thus Ctrl_T must be limited.
So this approach works pretty well if my formal generic parameter is
type T is tagged limited private;
This package allows any limited tagged type to be specialized as a
limited_controlled type (sort of).
MY CHALLENGE is : how to do the same thing with non-limited types ?
--
------------------------------------------------------------------------
Cyrille Comar, E-mail: comar@cs.nyu.edu
Gnat Project US phone: (212) 998-3489
next prev parent reply other threads:[~1994-12-09 17:26 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
1994-11-23 21:33 Ada 90 inheritance request? S M Ryan
1994-12-02 16:46 ` Tucker Taft
1994-12-09 17:26 ` Cyrille Comar [this message]
1994-12-11 18:47 ` Bob Duff
1994-12-12 3:15 ` Tucker Taft
1994-12-13 19:02 ` John Goodsen
1994-12-14 19:49 ` John Goodsen
1994-12-15 18:41 ` Robert I. Eachus
1994-12-19 18:58 ` John Goodsen
1994-12-20 10:40 ` Robert I. Eachus
1994-12-21 16:02 ` Norman H. Cohen
1994-12-22 1:21 ` Bob Duff
1994-12-17 13:55 ` Tucker Taft
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox