Newsgroups: comp.object,comp.lang.c++,comp.lang.ada,comp.lang.cobol,comp.lang.clos
Path: cantaloupe.srv.cs.cmu.edu!rochester!udel!news.mathworks.com!hookup!news.moneng.mei.com!uwm.edu!math.ohio-state.edu!jussieu.fr!news-rocq.inria.fr!news2.EUnet.fr!news.fnet.fr!ilog!news
From: davis@ilog.fr (Harley Davis)
Subject: Re: C++ not OOP? (Was: Language Efficiency
In-Reply-To: ncohen@watson.ibm.com's message of 18 Apr 1995 17:41:29 GMT
Message-ID: <DAVIS.95Apr19112448@passy.ilog.fr>
Lines: 39
Sender: news@ilog.fr
Nntp-Posting-Host: passy
Organization: Ilog SA, Gentilly, France
References: <dewar.797512974@gnat> <3mbmd5$s06@icebox.mfltd.co.uk>
	<D6uA77.Lqp@mcshub.dcss.mcmaster.ca> <3mcfbf$psl@acmez.gatech.edu>
	<3mcoh6$add@Starbase.NeoSoft.COM> <3mdrpf$3o9@disunms.epfl.ch>
	<dewar.797608300@gnat> <3mg45s$5r7@disunms.epfl.ch>
	<3mjc8c$630@crcnis3.unl.edu> <3n0tk9$149v@watnews1.watson.ibm.com>
Date: 19 Apr 1995 09:24:48 GMT
Xref: glinda.oz.cs.cmu.edu comp.object:29739 comp.lang.c++:123807 comp.lang.ada:28824 comp.lang.cobol:2852 comp.lang.clos:2880

In article <3n0tk9$149v@watnews1.watson.ibm.com> ncohen@watson.ibm.com (Norman H. Cohen) writes:

   |> Question:  Using single dispatch, how does one code a subroutine to display
   |> a given shape on a given device?
   |>
   |> Answer:  Well, you have to pick either the shape object or the device object
   |> to control dispatch.  The methods, then, will contain big cases around the
   |> type of the other object supplied.  For example, each device could act
   |> differently according to the shape given it (via some ugly case or switch type
   |> construction), or each shape could act differently according to the device
   |> given it (via another ugly case or switch type construction).

   This is obviously a poorly designed solution.  The right approach
   is to come up with an "abstract device" with concrete
   implementations corresponding to each actual device.  The routine
   to write a given shape on a given device dispatches based on the
   shape, passing the device object as a parameter.  The routine to
   write a given shape issues calls on the abstract device interface,
   and these calls dispatch based on the underlying concrete device.

This approach is not contradictory with the multiple dispatch
approach.  Multiple dispatch can enhance your solution.

Start with an abstract interface to devices.  Write routines for all
shapes which use this abstract interface.  Then, for speed critical
shape/device pairs, write more specific multimethods which use
underlying device implementation information for optimization.
Indeed, I believe this is the textbook approach to using multimethods.

-- Harley Davis
-- 

------------------------------------------------------------------------------
Harley Davis                            net: davis@ilog.fr
ILOG S.A.                               tel: +33 1 46 63 66 66
2 Avenue Gallini, BP 85                fax: +33 1 46 63 15 82
94253 Gentilly Cedex, France            url: http://www.ilog.com/

           Ilog Talk information: info@ilog.com
