comp.lang.ada
 help / color / mirror / Atom feed
* Using interfaces
@ 2018-06-02 15:20 gautier_niouzes
  2018-06-02 15:55 ` Jere
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: gautier_niouzes @ 2018-06-02 15:20 UTC (permalink / raw)


Hello,
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. 

with System;

package Test_interfaces is

  type Real is digits System.Max_Digits;

  type Box is record left, bottom, width, height : Real; end record;

  type Graphic_Figures is abstract tagged record bounding : Box; end record;
  
  procedure Set_Bounding_Box (figure: Graphic_Figures);
  --  This draws any kind of figure
  procedure Draw (figure: Graphic_Figures; parameter: Integer) is abstract;

  type Any_Device is interface;
  --  Callback method for filling a rectangle
  procedure Filled_Rectangle (device: Any_Device) is abstract;

  type Device_X is new Any_Device with null record;
  procedure Filled_Rectangle (device: Device_X);

  type Figure_A is new Graphic_Figures with null record;
  procedure Draw (figure: Figure_A; parameter: Integer);

  type Figure_A_on_Device_X is new Figure_A and Device_X with null record;

end Test_interfaces;

Now on Figure_A_on_Device_X GNAT tells me rightfully that Device_X must be an interface. Now if I have instead:

  type Figure_A_on_Device_X is new Figure_A and Any_Device with null record;
  procedure Filled_Rectangle (device: Figure_A_on_Device_X);

or in two steps,

  type Figure_A_on_Any_Device is abstract new Figure_A and Any_Device with null record;

  type Figure_A_on_Device_X is new Figure_A_on_Any_Device with null record;
  procedure Filled_Rectangle (device: Figure_A_on_Device_X);

this is okay but I would need to copy-paste the same implementation code of Filled_Rectangle for device X in the case of Figure_B and so on. Not nice!

How do I get something like Figure_A_on_Device_X ?
Am I expecting too much from interfaces?

TIA

Gautier
_____________________________________________________________
A free online game in Ada: http://pasta.phyrama.com/game.html

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

end of thread, other threads:[~2018-06-04  9:32 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-02 15:20 Using interfaces gautier_niouzes
2018-06-02 15:55 ` Jere
2018-06-02 17:00 ` Dmitry A. Kazakov
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

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