comp.lang.ada
 help / color / mirror / Atom feed
* Invoking Inherited Routines in Ada9x
@ 1991-12-05 17:16 Shaun Smith
  0 siblings, 0 replies; 3+ messages in thread
From: Shaun Smith @ 1991-12-05 17:16 UTC (permalink / raw)


   I'm not a member of the mailing list, but since ``Dear Ada'' isn't
entertaining 9X questions as yet she/he recommended I mail to it to find
an answer to my question.

  In Ada9x, does you know how a subclass subprogram can invoke the
subprogram with the same name defined by an ancestor.  This is achieved
in Smalltalk by sending a message to "super".  By sending to "super"
rather than "self", the next implementation of a method in the
inheritance hierarchy is invoked rather than the one supplied by the
class of the current object.  Is that clear?

Here's the scenario in C++:

eg.     class A {
 	  virtual void foo(); // virtual means can be redefined by subclasses
 	}

	class B : public C {
 	  void foo(); // "virtualness" inherited
  	}

	class C : public B {
 	  void foo(); // "virtualness" inherited
  	}


	// In class C implementation file
	void C::foo() {
	   B::foo(); // must qualify the inherited member function with the
		     // name of the parent which defines it.
	}


C++'s solution to this requirment results in brittle code since one has to
specifically identify the parent class which supplies the next most
specific implementation of a member function (method).

Back to my question.  I've had a look through the Ada9x documentation
and can't find anything about how this will be done.   One person
familiar with Ada suggested that perhaps the package name could be used
to specify which class's implementatation of "foo" was desired.  This
suffers from C++`s problem.  In addition, isn't is possible to define an
arbitrary number of classes within a package.

If someone knows the answer, or which document and section to look in,
please let me know (by email since I'm not on the list).  I'm just
trying to get a handle on how Ada9x approaches support for
object-oriented programming.

       Shaun

Shaun M. Smith                  | ssmith@mprgate.mpr.ca
MPR Teltech Ltd.                | mprgate.mpr.ca!ssmith@uunet.uu.net
8999 Nelson Way, Burnaby, BC    | ssmith%mprgate.mpr.ca@relay.ubc.ca
Canada, V5A 4B5, (604) 293-5345 | 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Invoking Inherited Routines in Ada9x
@ 1991-12-10 15:42 Larry Maturo
  0 siblings, 0 replies; 3+ messages in thread
From: Larry Maturo @ 1991-12-10 15:42 UTC (permalink / raw)


In article <9112051716.AA04270@merengue.mpr.ca> ssmith@MPRGATE.MPR.CA (Shaun Sm
ith) writes:
>
>   I'm not a member of the mailing list, but since ``Dear Ada'' isn't
>entertaining 9X questions as yet she/he recommended I mail to it to find
>an answer to my question.
>
>  In Ada9x, does you know how a subclass subprogram can invoke the
>subprogram with the same name defined by an ancestor.  This is achieved
>in Smalltalk by sending a message to "super".  By sending to "super"
>rather than "self", the next implementation of a method in the
>inheritance hierarchy is invoked rather than the one supplied by the
>class of the current object.  Is that clear?
>
>Here's the scenario in C++:
>
>eg.     class A {
> 	  virtual void foo(); // virtual means can be redefined by subclasses
> 	}
>
>	class B : public C {
> 	  void foo(); // "virtualness" inherited
>  	}
>
>	class C : public B {
> 	  void foo(); // "virtualness" inherited
>  	}
>
>
>	// In class C implementation file
>	void C::foo() {
>	   B::foo(); // must qualify the inherited member function with the
>		     // name of the parent which defines it.
>	}
>
>
>C++'s solution to this requirment results in brittle code since one has to
>specifically identify the parent class which supplies the next most
>specific implementation of a member function (method).
>
>Back to my question.  I've had a look through the Ada9x documentation
>and can't find anything about how this will be done.   One person
>familiar with Ada suggested that perhaps the package name could be used
>to specify which class's implementatation of "foo" was desired.  This
>suffers from C++`s problem.  In addition, isn't is possible to define an
>arbitrary number of classes within a package.
>
>If someone knows the answer, or which document and section to look in,
>please let me know (by email since I'm not on the list).  I'm just
>trying to get a handle on how Ada9x approaches support for
>object-oriented programming.
>
>       Shaun
>
>Shaun M. Smith                  | ssmith@mprgate.mpr.ca
>MPR Teltech Ltd.                | mprgate.mpr.ca!ssmith@uunet.uu.net
>8999 Nelson Way, Burnaby, BC    | ssmith%mprgate.mpr.ca@relay.ubc.ca
>Canada, V5A 4B5, (604) 293-5345 | 
>


I have heard somewhere that Ada 9X might have handle object oriented things
the way Oberon 2 does.  If so, in Oberon-2 the above is handled by using a
caret after a routine name to refer to it's anscestor routine so the above in
Oberon 2 would be something like the below (note: I have never programmed in
Oberon-2 so this is approximate at best):


TYPE A : RECORD (* The base type *)
           I:INTEGER;
           B:BOOLELAN;
         END;

TYPE B : RECORD (A) (* Extends A *)
           R: REAL;
         END;

TYPE C : RECORD (B) (* Extends B *)
           C : CHAR;
         END;

PROCEDURE foo (p1:A) (parameter list for foo); (* This foo bound to TYPE A *)
BEGIN
  ...
END foo;


PROCEDURE foo (p2:B) (parameter list for foo); (* This foo bound to TYPE B *)
BEGIN
  ...
END foo;


PROCEDURE foo (p3:C) (x:A); (* This foo bound to TYPE C with parameter of type 
A *)
BEGIN
  foo^(x);  (* This invokes the foo bound to TYPE A *)
END foo;



I'd be interested to see if Ada 9X is indeed implementing OOP this way.  Any
comments?

+-----------------------------------+----------------------------------------+
|                                   |                                        |
| Larry Maturo                      | Opinions expressed herein must be      |
| Applied Research Laboratories     | yours, neither I nor my employer have  |
| University of Texas at Austin     | any.                                   |
| P.O. Box 8029                     +----------------------------------------+
| Austin, Texas 78713-8029          |                                        |
|                                   | When you're as great as I am it's hard |
| larry@titan.tsd.arlut.utexas.edu  | to be modest, but I succeed where      |
|                                   | others fail.                           |
+-----------------------------------+----------------------------------------+

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Invoking Inherited Routines in Ada9x
@ 1991-12-11 15:57 Alex Blakemore
  0 siblings, 0 replies; 3+ messages in thread
From: Alex Blakemore @ 1991-12-11 15:57 UTC (permalink / raw)


In article <9112051716.AA04270@merengue.mpr.ca> ssmith@MPRGATE.MPR.CA (Shaun Sm
ith) writes:
>  In Ada9x, does [sic] you know how a subclass subprogram can invoke the
>subprogram with the same name defined by an ancestor.  This is achieved
>in Smalltalk by sending a message to "super".  By sending to "super"
>rather than "self", the next implementation of a method in the
>inheritance hierarchy is invoked rather than the one supplied by the
>class of the current object.  Is that clear?

This is described in the mapping rationale document version 3.1
August 1991.  An example in section 4.2.3.1 pages 4-10 to 4-11
shows how to call a subprogram can invoke the subprogram which
it is overriding using explicit type conversion.
An abbreviated version follows (I have left out some lines,
but added none other than comments):

package new_system is
  type alert is tagged  -- dispatching (polymorphic?) type
    record
      message : text;
    end record;
  procedure handle (A : in out alert);
end new_system;

with new_system;
package medium_level is
  type medium_alert is new new_system.alert with -- Ada9X type extension
    record
      action_officer : person;
     end record;
  procedure handle (MA : in out medium_alert);
end medium_level;

package body medium_level is
  use new_system;
  procedure handle (MA : in out medium_alert) is
  begin
    handle(alert(ma));  -- calls new_system.handle
    ma.action_officer := assign_volunteer;
  end handle;
end medium_level;

For more info read the mapping rationale and mapping specifications
douments from ajpo.sei.cmu.edu (read the rational first)

>C++'s solution to this requirment results in brittle code since one has to
>specifically identify the parent class which supplies the next most
>specific implementation of a member function (method).

Ada's solution seems similar to C++'s in that the subclass must
name the superclass to invoke the parent method (using OO speak)
I assume you find that brittle because it makes it difficult
to rearrange the inheritance hierarchy ? perhaps to add a new 
intermediate level.

On the other hand this solution fits with Ada83 syntax and
semantics well.  Explicit type conversion allows the Ada83
overloading to resolve at compile time which subprogram to invoke.

If you have a better suggestion, post it to or
send it to the people who can do something about it at
ada9x-mrt@inmet.inmet.com

The mapping rationale claims near the end of that section:
"Each body for HANDLE encloses just the code relevant to the type,
and delegates additional processing to an ancestor with explicit
type conversion.  This is more flexible than the super pseudo-variable
of Smalltalk-80 and retains static type checking."

>In addition, isn't is possible to define an
>arbitrary number of classes within a package.

Yes just as it is possible to declare an arbitrary number
of types within a package.  Sometimes that is useful, but that
doesnt mean it is always good design.  I always try to put one
ADT per package as a rule of thumb, perhaps with some supporting types.
I imagine adding inheritance wont change that.

By the way, a type class in Ada9X is SET of types
which share common operations and are organized in a class
hierarchy (tree).  This is different than the normal OO
definition of class which corresponds mode closely to an
Ada9X type.
-- 
---------------------------------------------------------------------
Alex Blakemore           blakemore@software.org        (703) 742-7125
Software Productivity Consortium  2214 Rock Hill Rd, Herndon VA 22070

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~1991-12-11 15:57 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1991-12-05 17:16 Invoking Inherited Routines in Ada9x Shaun Smith
  -- strict thread matches above, loose matches on Subject: below --
1991-12-10 15:42 Larry Maturo
1991-12-11 15:57 Alex Blakemore

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