comp.lang.ada
 help / color / mirror / Atom feed
From: ncohen@watson.ibm.com (Norman H. Cohen)
Subject: Re: Real OO
Date: 1996/03/22
Date: 1996-03-22T00:00:00+00:00	[thread overview]
Message-ID: <4iuvmi$113p@watnews1.watson.ibm.com> (raw)
In-Reply-To: DonJqn.755@assip.csasyd.oz

In article <DonJqn.755@assip.csasyd.oz>, donh@syd.csa.com.au
(Don Harrison) writes: 

|>                                         In Eiffel, there is only one species of
|> type - the class - which may be viewed as specific or class-wide depending on
|> the context. This makes modelling considerably easier.
|>
|> Ada complicates matters by forcing an atificial distinction of specific versus
|> classwide depending on usage. Since the formal and actual parameters of an
|> operation may be either specific or classwide, the number of possible
|> combinations is 4 compared with 1 in Eiffel. To my mind, this is 4 times more
|> complicated than is really needed.

This is not an artificial distinction.  Let us consider actual parameters
and formal parameters separately.

In the case of actual parameters, it is a formalization of the
distinction that Bertrand Meyer recognizes between the static type and
the dynamic type of a reference.  Think of an Ada actual parameter of a
specific type as an Eiffel reference whose dynamic type is known to be
identical to its static type.  A method call can be far more efficient if
this knowledge is conveyed to the compiler, and it is common in practice
for this knowledge to be available.  (The extra efficiency arises not
only from saving a cycle or two for an indirect jump, but also because of
the possibility of inlining the method body or performing precise
interprocedural analysis.)

In the case of formal parameters, the use of a classwide type or specific
type reflects the distinction between a single type and the hierarchy of
types descended (in zero or more steps) from that type.  (In Eiffel, the
word "class" refers to any one of these types; in Ada, the word "class"
refers to the hierarchy, so "classwide" means "hierarchy-wide".)  A
classwide subprogram (i.e., one with classwide formal parameters) is one
whose algorithm is the same for all objects in the hierarchy.  A
dispatching subprogram (i.e., one with specific formal parameters) is one
whose algorithm depends on the tag (in Eiffel terms, the dynamic type) of
the actual parameter.  The body of a classwide subprogram relies only on
properties common to all types in the hierarchy, i.e., features
introduced at the root of the hierarchy.  These may include record
components, other classwide subprograms, and dispatching operations.

For a one-parameter subprogram, the effect of a classwide subprogram
could be achieved by a dispatching subprogram that is never overridden.
Making it classwide simply documents the fact that the algorithm does not
depend on the tag of the parameter, and causes the compiler to catch any
attempt to override.  The real power of a classwide program arises with
multiple parameters.  In Eiffel, dispatching is controlled by the one
object whose method is invoked (the x in x.f()).  In an Ada dispatching
subprogram, there can be multiple parameters controlling the dispatching.
Consider a hierarchy for geometric figures, with Shape_Type at the root
and types such as Circle_Type, Triangle_Type, and Rectangle_Type at the
leaves.  There may be a dispatching operation Corresponding_Parts_Equal
defined (as an abstract function) for Shape_Type and overridden for each
shape.  For example: 

   function Corresponding_Parts_Equal (C1, C2: Circle_Type) return Boolean is
   begin
      return C1.Radius = C2.Radius;
   end Corresponding_Parts_Equal;


   function Corresponding_Parts_Equal
      (R1, R2: Rectangle_Type) return Boolean is
   begin
      return
         (R1.Base = R2.Base and R1.Height = R2.Height) or
         (R1.Base = R2.Height and R1.Height = R2.Base);
   end Corresponding_Parts_Equal;

Each time a new kind of shape is introduced to the hierarchy, a new
overriding version of Corresponding_Parts_Equal, concerned only with the
features of that kind of shape, is written.

The call Corresponding_Parts_Equal(Shape1, Shape2), where Shape1 and
Shape2 are of type Shape_Type'Class (in Eiffel terms, their static types
are Shape_Type and their dynamic types are unknown), will dispatch to the
first body above if the dynamic types of Shape1 and Shape2 are both
Circle_Type, to the second body above if the dynamic types are both
Rectangle_Type, and so forth.  But if Shape1 and Shape2 have different
dynamic tags, there is no sensible way to check that their corresponding
parts are equal, and a run-time error results.  That leaves the problem
of how to determine whether two arbitrary Shape_Type'Class values,
possibly with different tags, are congruent, and this is where classwide
subprograms come in.  There is no requirement that the parameters of a
classwide subprogram have the same tag.  Therefore, we can write: 

    function Congruent (Shape1, Shape2: Shape_Type'Class) return Boolean is
    begin
       return
          Shape1'Tag = Shape2'Tag and then
          Corresponding_Parts_Equal (Shape1, Shape2);
    end Congruent;

When the shapes have different tags, the function immediately returns
False without invoking Corresponding_Parts_Equal.

--
Norman H. Cohen    ncohen@watson.ibm.com




  reply	other threads:[~1996-03-22  0:00 UTC|newest]

Thread overview: 218+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <4id031$cf9@dayuc.dayton.saic.com>
1996-03-18  0:00 ` Real OO Norman H. Cohen
1996-03-18  0:00   ` The Right Reverend Colin James III
1996-03-19  0:00     ` Norman H. Cohen
1996-03-20  0:00       ` Norman Cohen giving IBM a bad name The Right Reverend Colin James III
1996-03-20  0:00         ` Colin James III giving humans a bad name (was Re: Norman Cohen giving IBM a bad name) David Emery
1996-03-20  0:00           ` Mark R Okern - F95
1996-03-20  0:00             ` Real OO John G. Volan
1996-03-21  0:00               ` Scott Leschke
1996-03-21  0:00                 ` Robert A Duff
1996-03-21  0:00                 ` Norman H. Cohen
1996-03-22  0:00                 ` Don Harrison
1996-03-21  0:00             ` Colin James III giving humans a bad name (was Re: Norman Cohen giving IBM a bad name) Richard A. O'Keefe
1996-03-21  0:00               ` Robert Dewar
1996-03-20  0:00         ` Norman Cohen giving IBM a bad name Brian & Karen Bell
1996-03-20  0:00         ` Real OO Dale Stanbrough
1996-03-21  0:00           ` Richard Pitre
1996-03-20  0:00         ` Norman Cohen giving IBM a bad name Dave Retherford
1996-03-21  0:00         ` Kent Mitchell
1996-03-22  0:00         ` Robert Munck
1996-03-22  0:00           ` Mark Brennan
1996-03-22  0:00             ` David Curry
1996-03-23  0:00         ` Tom Reid
1996-03-21  0:00       ` Real OO Don Harrison
1996-03-21  0:00   ` Colin James III giving humans a bad name (was Re: Norman Cohen giving IBM a bad name) Ulrich Windl
1996-03-20  0:00 ` Real OO Don Harrison
1996-03-22  0:00 ` Don Harrison
1996-03-22  0:00   ` Norman H. Cohen [this message]
1996-03-27  0:00     ` Don Harrison
1996-03-27  0:00       ` Norman H. Cohen
1996-03-28  0:00         ` Jacob Gore
1996-04-04  0:00         ` Don Harrison
1996-04-04  0:00           ` Robb Nebbe
1996-04-04  0:00           ` Laurent Guerby
1996-04-04  0:00           ` Jon S Anthony
1996-04-04  0:00           ` Tucker Taft
1996-04-04  0:00             ` Tucker Taft
1996-04-12  0:00               ` Don Harrison
1996-04-12  0:00             ` Don Harrison
1996-04-15  0:00               ` Robert I. Eachus
1996-04-19  0:00                 ` Don Harrison
1996-04-19  0:00                   ` Matt Kennel
1996-04-20  0:00                     ` Bob Hathaway
1996-04-23  0:00                     ` Don Harrison
1996-03-22  0:00   ` Norman H. Cohen
1996-03-26  0:00     ` Don Harrison
1996-03-26  0:00       ` Norman H. Cohen
1996-03-29  0:00         ` Don Harrison
1996-03-27  0:00       ` Thomas Beale
1996-03-28  0:00         ` Don Harrison
1996-03-23  0:00   ` Joachim Durchholz
1996-03-26  0:00     ` Norman H. Cohen
1996-04-04  0:00       ` Don Harrison
1996-04-04  0:00         ` Jon S Anthony
1996-04-12  0:00           ` Don Harrison
1996-04-17  0:00             ` Jon S Anthony
1996-04-19  0:00               ` Don Harrison
1996-04-19  0:00                 ` Jon S Anthony
1996-04-23  0:00                   ` Don Harrison
1996-04-24  0:00                     ` Don Harrison
1996-04-29  0:00                     ` Jon S Anthony
1996-04-30  0:00                       ` Robert Dewar
1996-04-30  0:00                         ` Amit Patel
1996-04-30  0:00                           ` Robert A Duff
1996-05-07  0:00                             ` Amit Patel
1996-05-01  0:00                           ` Norman H. Cohen
1996-05-01  0:00                             ` Colin James III (The Rt Rev'd)
1996-05-07  0:00                             ` Amit Patel
1996-04-30  0:00                         ` Robert A Duff
1996-04-30  0:00                           ` Robert Dewar
1996-05-01  0:00                             ` Richard Bielak
1996-04-30  0:00                           ` Amit Patel
1996-05-01  0:00                           ` Adam Beneschan
1996-05-02  0:00                             ` Ell
1996-05-01  0:00                         ` Don Harrison
1996-05-01  0:00                           ` David Hopwood
1996-05-03  0:00                             ` Don Harrison
1996-05-01  0:00                           ` Don Harrison
1996-05-02  0:00                             ` Robert A Duff
1996-05-03  0:00                               ` Don Harrison
1996-05-03  0:00                                 ` Robert A Duff
1996-05-06  0:00                                   ` Don Harrison
1996-05-06  0:00                                     ` Robert A Duff
1996-05-06  0:00                                     ` Robb Nebbe
1996-05-02  0:00                           ` Robert A Duff
1996-05-03  0:00                             ` Don Harrison
1996-05-10  0:00                             ` Don Harrison
1996-05-01  0:00                         ` AdaWorks
1996-05-08  0:00                         ` Joachim Durchholz
1996-05-03  0:00                       ` Don Harrison
1996-05-03  0:00                         ` Dave Fitch
1996-05-07  0:00                         ` Jon S Anthony
1996-04-30  0:00                     ` Joachim Durchholz
1996-04-30  0:00                     ` Jon S Anthony
1996-05-01  0:00                       ` Matt Kennel
1996-05-03  0:00                         ` Don Harrison
1996-05-02  0:00                       ` Don Harrison
1996-05-02  0:00                         ` Robert I. Eachus
1996-05-02  0:00                         ` Jon S Anthony
1996-05-03  0:00                           ` Don Harrison
1996-05-06  0:00                             ` Jon S Anthony
1996-05-06  0:00                         ` Jon S Anthony
1996-05-06  0:00                       ` Don Harrison
1996-05-06  0:00                         ` Don Harrison
1996-05-07  0:00                         ` Jon S Anthony
1996-05-13  0:00                           ` Don Harrison
1996-05-09  0:00                         ` Jon S Anthony
1996-04-19  0:00                 ` Multiple Dispatch in Ada 95 (Was Re: Real OO) Brian Rogoff
1996-04-21  0:00                   ` Brian Rogoff
1996-04-19  0:00                 ` Robert I. Eachus
1996-04-20  0:00                 ` Brian Rogoff
1996-04-21  0:00                   ` Robert A Duff
1996-04-24  0:00                 ` Real OO Joachim Durchholz
1996-05-01  0:00                   ` Matt Kennel
1996-05-02  0:00                     ` Don Harrison
1996-05-07  0:00                   ` Joachim Durchholz
1996-05-08  0:00                   ` Jon S Anthony
1996-05-09  0:00                   ` Robert I. Eachus
1996-04-30  0:00                 ` Jon S Anthony
1996-05-03  0:00                   ` Don Harrison
1996-05-07  0:00                     ` Jon S Anthony
1996-04-30  0:00                 ` Joachim Durchholz
1996-05-08  0:00                   ` Joachim Durchholz
1996-05-10  0:00                   ` Jon S Anthony
1996-05-02  0:00                 ` Jon S Anthony
1996-05-06  0:00                 ` Jon S Anthony
1996-04-08  0:00         ` Norman H. Cohen
1996-04-08  0:00           ` Robert A Duff
1996-04-09  0:00             ` Norman H. Cohen
1996-04-10  0:00           ` Don Harrison
1996-04-11  0:00           ` Jacob Gore
1996-04-12  0:00           ` Don Harrison
1996-04-12  0:00             ` Jacob Gore
1996-04-16  0:00               ` Don Harrison
1996-04-12  0:00           ` Don Harrison
1996-04-12  0:00             ` Jon S Anthony
1996-04-13  0:00               ` Robert A Duff
1996-04-12  0:00             ` Matt Kennel
1996-04-15  0:00               ` Don Harrison
1996-04-16  0:00             ` Jon S Anthony
1996-04-09  0:00         ` Valery CROIZIER
1996-04-09  0:00         ` Jon S Anthony
1996-04-09  0:00       ` Joachim Durchholz
1996-05-02  0:00       ` Joachim Durchholz
1996-05-05  0:00         ` Robert A Duff
1996-05-05  0:00           ` Robert Dewar
1996-05-06  0:00         ` Norman H. Cohen
1996-05-07  0:00           ` Ada terminology (was Re: Real OO) David Hopwood
1996-05-07  0:00             ` The Right Reverend Colin James III
1996-05-07  0:00             ` Dave Jones
1996-05-07  0:00             ` Tucker Taft
1996-05-07  0:00               ` The Right Reverend Colin James III
1996-05-08  0:00               ` bill.williams
1996-05-07  0:00           ` Real OO Don Harrison
1996-05-07  0:00             ` Jon S Anthony
1996-05-08  0:00               ` Don Harrison
1996-05-08  0:00             ` Norman H. Cohen
1996-05-08  0:00               ` Robert A Duff
1996-05-10  0:00                 ` Matt Kennel
1996-05-10  0:00                   ` Robert A Duff
1996-05-14  0:00                     ` Matt Kennel
1996-05-15  0:00                       ` Robert A Duff
1996-05-07  0:00         ` Amit Patel
1996-05-07  0:00           ` The Right Reverend Colin James III
1996-05-08  0:00           ` Don Harrison
1996-05-08  0:00             ` Juergen Schlegelmilch
     [not found]               ` <Dr4538.D27@assip.csasyd.oz>
1996-05-09  0:00                 ` Richard Riehle
1996-05-10  0:00                   ` Tucker Taft
1996-05-13  0:00                     ` Don Harrison
1996-05-13  0:00                       ` Tucker Taft
1996-05-14  0:00                         ` Don Harrison
1996-05-14  0:00                           ` Steve Tynor
1996-05-14  0:00                             ` Robert A Duff
1996-05-15  0:00                             ` Don Harrison
1996-05-14  0:00                           ` Robert A Duff
1996-05-15  0:00                           ` Steve Tynor
1996-05-15  0:00                             ` Robert A Duff
1996-05-16  0:00                           ` James McKim
1996-05-18  0:00                             ` Matt Kennel
1996-05-20  0:00                               ` James McKim
1996-05-22  0:00                                 ` Matt Kennel
1996-05-14  0:00                         ` Roger Browne
1996-05-14  0:00                         ` Joachim Durchholz
1996-05-15  0:00                         ` Alexander Kjeldaas
1996-05-15  0:00                         ` Steve Tynor
1996-05-19  0:00                         ` Piercarlo Grandi
1996-05-14  0:00                   ` James McKim
1996-05-15  0:00                     ` Juergen Schlegelmilch
1996-05-09  0:00                 ` Juergen Schlegelmilch
1996-05-20  0:00               ` Joachim Durchholz
1996-05-07  0:00       ` Joachim Durchholz
1996-05-09  0:00         ` Don Harrison
1996-05-09  0:00           ` Joachim Durchholz
1996-05-09  0:00           ` Jon S Anthony
1996-04-02  0:00     ` Detecting type mismatch at compile time (was Re: Real OO) Robert I. Eachus
1996-04-03  0:00       ` Richard Bielak
1996-04-04  0:00       ` Don Harrison
1996-03-28  0:00   ` Real OO Joachim Durchholz
1996-03-29  0:00     ` Norman H. Cohen
1996-03-30  0:00       ` John G. Volan
1996-03-26  0:00 ` Jon S Anthony
1996-03-29  0:00 ` Joachim Durchholz
1996-04-04  0:00   ` Don Harrison
1996-04-04  0:00     ` Dominique Colnet
1996-04-04  0:00     ` Steve Tynor
1996-04-08  0:00       ` Norman H. Cohen
1996-04-09  0:00         ` Matt Kennel
1996-04-08  0:00     ` Matt Kennel
1996-04-09  0:00       ` Norman H. Cohen
1996-04-09  0:00     ` Robert C. Martin
1996-04-10  0:00     ` J. Kanze
1996-05-02  0:00 Bob Crispen
     [not found] <DoDLr7.JDB@world.std.com>
     [not found] ` <4if7s5$bfk@ra.nrl.navy.mil>
     [not found]   ` <DoDqH4.29v@world.std.com>
1996-03-26  0:00     ` AdaWorks
1996-03-29  0:00   ` Brian Rogoff
     [not found] <JSA.96Mar13143956@organon.com>
1996-03-15  0:00 ` Don Harrison
     [not found] <4hneps$1238@watnews1.watson.ibm.com>
     [not found] ` <Do3F1K.4xG@assip.csasyd.oz>
     [not found]   ` <4i455s$ijq@watnews1.watson.ibm.com>
1996-03-15  0:00     ` Don Harrison
     [not found]       ` <DoBH80.9u9@world.std.com>
1996-03-15  0:00         ` Richard Pitre
1996-03-15  0:00         ` Mark A Biggar
1996-03-16  0:00     ` Des  Kenny
replies disabled

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