comp.lang.ada
 help / color / mirror / Atom feed
From: eachus@spectre.mitre.org (Robert I. Eachus)
Subject: Re: Multiple dispatch  (was Re: C++ not OOP?)
Date: 1995/04/19
Date: 1995-04-19T00:00:00+00:00	[thread overview]
Message-ID: <EACHUS.95Apr19194215@spectre.mitre.org> (raw)
In-Reply-To: 3mbmd5$s06@icebox.mfltd.co.uk

In article <3n1als$ksi@no-names.nerdc.ufl.edu> kem@prl.ufl.edu (Kelly Murray) writes:

 > But we have a device that can do a draw-line real fast, so we want to
 > use it when we can, for example, on a square shape.  We must know that
 > a shape can provide the line information.  Thus, the draw method is
 > really specialized for not a square, but a lined-shaped object which
 > a square should inherit from, and return

 >  (defmethod draw ((dev line-device) (shape lined-shape))
 >    (dolist (line (shape-lines shape))
 >     (draw-line dev line)))

 > I believe this is basically the same strategy that Robert Eachus
 > has outlined.  I don't see how it could fit easily into a 
 > single-dispatch model.  Which object is doing the dispatching?
 > Do we make the device explicitely ask the shape at run-time 
 > if it can support a given operation? :

   No.  I may not have explained it well.  Let me see if I can use
your example to elucidate.  First, in Ada 95--and in some other
OO-languages--objects may be passed as non-dispatching parameters,
then used internal to the called procedure to dispatch on.  So you can
end up doing two-level dispatching, in this case first on the shape,
then on the device.

   If you specified drawing a square in terms of drawing four lines:

   procedure Draw(S: Square; L: Location; D: Device) is
   begin
      Draw_Line(Make_Line(S.Side,Horizontal),L, D);
      Draw_Line(Make_Line(S.Side,Vertical),L, D);
      Draw_Line(Make_Line(S.Side,Vertical),L+Horizontal_Displacement(S.Side),
           D);
      Draw_Line(Make_Line(S.Side,Horizontal),L+Vertical_Displacement(S.Side),
           D);
   end Draw;

   If we defined Line and Point as part of the primitive set of
operations for all devices, this is all we have to do to add drawing
squares.  (Notice that in Ada 95, the dispatching parameter can be
located anywhere in the parameter list.) Regular pentagons might be a
bit more work, but the principle is the same.

   (Note that to make things neater, you probably have some
definitions of the form:

   procedure Draw(S: Line; L: Location; D: Device) is
   begin Draw_Line(S,L,D); end Draw;

   to do the outer dispatch where the shape to be drawn is a run-time
parameter.  This is the "extra" bookkeeping required by not having
multiple dispatch in the language.) 

   Now when adding a new device, the requirements might be to provide
definitions for Point, Line, Circle, and Cubic_Spline.  Other
primitives could be provided if easily supported--say Ellipse,
Parabola, and Polygon, and even possibly Square and Rectangle--but
these would have default definitions in terms of the other primitives.
The definitions would be overridden if there was a more efficient
direct implementation for some device, and then only if you wanted the
extra efficiency.

  > Or make the shapes explicitely check for the fast operations?

    No, that should be implicit in the call tree.  In the above
example, Draw for a Square calls Line.  If for some device, Line
calls Point, that will occur within Line.  If there was a default
Square definition and it was overridden for some device, fine.

    An alternative is to have two ways to draw some shape, and have a
nested case statement to choose the "better" method based on the
device.  Seems like a maintenance nightmare, but the only damage done
if version control fails is that the less efficient method will be
used.

  > To add a device or shape, create a new index, and a bigger table.

   Arrrgh!  In my model you should never have to "recompile the
world."



--

					Robert I. Eachus

with Standard_Disclaimer;
use  Standard_Disclaimer;
function Message (Text: in Clever_Ideas) return Better_Ideas is...




  parent reply	other threads:[~1995-04-19  0:00 UTC|newest]

Thread overview: 68+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1995-04-02  0:00 Language Efficiency Robert C. Bethel
1995-04-04  0:00 ` Bob Kitzberger
1995-04-05  0:00   ` Mike Wilson
1995-04-05  0:00     ` Larry Kilgallen
1995-04-05  0:00     ` David Weller
1995-04-04  0:00 ` Harold P Zbiegien
1995-04-04  0:00   ` Larry Kilgallen
1995-04-06  0:00     ` Robert Dewar
1995-04-04  0:00   ` Kennel
1995-04-05  0:00     ` Ray Toal
1995-04-07  0:00     ` Robert Dewar
     [not found]       ` <3m9o9q$igf@stc06.ctd.ornl.gov>
     [not found]         ` <D6ss6z.Gvw@mcshub.dcss.mcmaster.ca>
     [not found]           ` <dewar.797512974@gnat>
1995-04-19  0:00             ` Adam Beneschan
1995-04-19  0:00               ` Robert Dewar
     [not found]             ` <3mbmd5$s06@icebox.mfltd.co.uk>
1995-04-19  0:00               ` C++ not OOP? (Was: " Harley Davis
     [not found]               ` <D6uA77.Lqp@mcshub.dcss.mcmaster.ca>
     [not found]                 ` <dewar.797566928@gnat>
     [not found]                   ` <D6vxDG.JKJ@mcshub.dcss.mcmaster.ca>
     [not found]                     ` <dewar.797636710@gnat>
     [not found]                       ` <D6xF22.38H@mcshub.dcss.mcmaster.ca>
     [not found]                         ` <dewar.797729041@gnat>
     [not found]                           ` <3msdop$862@stc06.ctd.ornl.gov>
1995-04-19  0:00                   ` Paul Graham
1995-04-19  0:00                     ` Robert Dewar
     [not found]                 ` <3mcfbf$psl@acmez.gatech.edu>
     [not found]                   ` <3mgnkc$e3j@atlantis <3muaif$46u@atlantis.utmb.edu>
     [not found]                     ` <3n0lsu$nio@druid.borland.com>
     [not found]                       ` <3n0uvi$8jt@atlantis.utmb.edu>
1995-04-19  0:00                         ` C++ not OOP? (Was: " Fernando Mato Mira
1995-04-19  0:00                           ` Curtis Bass
1995-04-19  0:00                             ` David Weller
1995-04-20  0:00                               ` Curtis Bass
1995-04-20  0:00                                 ` David Weller
1995-04-20  0:00                                   ` Robert Dewar
1995-04-21  0:00                                     ` Curtis Bass
1995-04-21  0:00                                       ` Robert Dewar
1995-04-20  0:00                                   ` Curtis Bass
1995-04-21  0:00                                     ` Robert Martin
1995-04-21  0:00                                       ` Ed Osinski
1995-04-21  0:00                                     ` Fernando Mato Mira
1995-04-21  0:00                                 ` Robert Martin
1995-04-20  0:00                         ` Matt Austern
1995-04-21  0:00                         ` Robert Martin
1995-04-21  0:00                           ` Curtis Bass
1995-04-21  0:00                         ` Matt Austern
1995-04-22  0:00                           ` Robert Martin
1995-04-22  0:00                             ` OOAD courses by Object Mentor cjames
1995-04-22  0:00                           ` C++ not OOP? (Was: Language Efficiency David Weller
1995-04-21  0:00                         ` Ed Osinski
1995-04-21  0:00                         ` Robert Martin
1995-04-21  0:00                           ` Curtis Bass
     [not found]                   ` <3mcoh6$add@Starbase.NeoSoft.COM>
     [not found]                     ` <3mdrpf$3o9@disunms.epfl.ch>
     [not found]                       ` <dewar.797608300@gnat>
     [not found]                         ` <3mg45s$5r7@disunms.epfl.ch>
     [not found]                           ` <3mjc8c$630@crcnis3.unl.edu>
     [not found]                             ` <D71Gs9.2FG@nntpa.cb.att.com>
     [not found]                               ` <EACHUS.95Apr17162921@spectre.mitre.org>
     [not found]                                 ` <3n1als$ksi@no-names.nerdc.ufl.edu>
1995-04-19  0:00                                   ` Multiple dispatch (was Re: C++ not OOP?) Fernando Mato Mira
     [not found]                           ` <1995Apr13.152104@di.epfl.ch>
1995-04-21  0:00                             ` C++ not OOP? (Was: Language Efficiency James McKim
     [not found]                   ` <3mgnkc$e3j@atlantis.utmb.edu>
     [not found]                     ` <1995Apr13.180317.3308@rcmcon.com>
     [not found]                       ` <3muaif$46u@atlantis.utmb.edu>
1995-04-21  0:00                         ` Robert Martin
1995-04-21  0:00                           ` Curtis Bass
1995-04-21  0:00                             ` Robert Dewar
1995-04-22  0:00                             ` Robert Martin
     [not found]                     ` <3mk65q$1kti@watnews1.watson.ibm.com>
     [not found]                       ` <3muavq$46u@atlantis.utmb.edu>
1995-04-21  0:00                         ` Norman H. Cohen
1995-04-21  0:00                           ` Curtis Bass
1995-04-19  0:00               ` Multiple dispatch (was Re: C++ not OOP?) Kenneth Almquist
1995-04-19  0:00               ` Robert I. Eachus [this message]
1995-04-21  0:00               ` Robert I. Eachus
1995-04-21  0:00               ` C++ not OOP? (Was: Language Efficiency Norman H. Cohen
1995-04-21  0:00                 ` Fernando Mato Mira
1995-04-21  0:00                   ` Erik Naggum
     [not found]               ` <MATT.95Apr17124932@physics10.berkeley.edu>
     [not found]                 ` <3mujnl$4u8@atlantis.utmb.edu>
1995-04-20  0:00                   ` ron house
1995-04-21  0:00                   ` Robert Martin
1995-04-21  0:00                     ` Curtis Bass
     [not found]         ` <dewar.797469506@gnat>
     [not found]           ` <1995Apr10.095958@di.epfl.ch>
     [not found]             ` <dewar.797513130@gnat>
     [not found]               ` <1995Apr10.165638@di.epfl.ch>
     [not found]                 ` <D6yGqv.4BG@nntpa.cb.att.com>
1995-04-21  0:00                   ` Fergus Henderson
1995-04-22  0:00                     ` Kenneth Almquist
1995-04-19  0:00       ` Fergus Henderson
1995-04-19  0:00         ` Robert Dewar
1995-04-20  0:00           ` Kennel
1995-04-19  0:00             ` Robert Dewar
1995-04-20  0:00   ` Matt Austern
1995-04-21  0:00   ` Robert I. Eachus
1995-04-05  0:00 ` Lawrence Free/ A.F. Software Services
1995-04-05  0:00 ` Mitch Gart
1995-04-06  0:00 ` Ken Leidner
1995-04-06  0:00   ` Larry Kilgallen
replies disabled

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