From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Using interfaces
Date: Sat, 2 Jun 2018 19:00:15 +0200
Date: 2018-06-02T19:00:15+02:00 [thread overview]
Message-ID: <peuiev$1mol$1@gioia.aioe.org> (raw)
In-Reply-To: 795d1d54-0868-4745-8132-b38165494f39@googlegroups.com
On 2018-06-02 17:20, gautier_niouzes@hotmail.com wrote:
> I am developing a package for displaying some kinds of figures on an open set of devices. I'm trying to use interfaces for that.
This is full multiple dispatch [*]:
procedure Draw
( Shape : Figure;
Surface : in out Device
) is abstract; -- This is not Ada!
Interfaces is no [direct] help.
Usually multiple dispatch is replaced with cascaded dispatch. You first
dispatch on the figure and then on the device from the implementation of
Draw:
type Device is limited interface;
-- Drawing primitives
procedure Draw_Filled_Rectangle
( Surface : in out Device;
Box : Rectangle;
Color : RGBA_Color
) is abstract;
...
type Figure is interface;
procedure Draw
( Shape : Figure;
Surface : in out Device'Class -- No dispatch
) is abstract;
type Filled_Rectangle is new Figure with record
Position : Box;
Color : RGBA_Color;
end record;
overriding
procedure Draw
( Shape : Filled_Rectangle;
Surface : in out Device'Class
);
procedure Draw
( Shape : Filled_Rectangle;
Surface : in out Device'Class
) is
begin
Surface.Draw_Filled_Rectangle (Shape.Position, Shape.Color);
end Draw;
This is too simple to work always in practice. There is no replacement
for multiple dispatch.
-------------------------------
* A simplified form of multiple dispatch is multi-method when only one
types hierarchy is involved, like in arithmetic operations. Full
multiple dispatch is when different type hierarchies share operations
like Figure and Device share Draw.
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
next prev parent reply other threads:[~2018-06-02 17:00 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-02 15:20 Using interfaces gautier_niouzes
2018-06-02 15:55 ` Jere
2018-06-02 17:00 ` Dmitry A. Kazakov [this message]
2018-06-02 17:22 ` Jeffrey R. Carter
2018-06-02 18:43 ` Dan'l Miller
2018-06-03 2:11 ` Shark8
2018-06-03 3:06 ` Dan'l Miller
2018-06-03 7:06 ` Dmitry A. Kazakov
2018-06-04 9:32 ` gautier_niouzes
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox