comp.lang.ada
 help / color / mirror / Atom feed
From: gautier_niouzes@hotmail.com
Subject: Using interfaces
Date: Sat, 2 Jun 2018 08:20:51 -0700 (PDT)
Date: 2018-06-02T08:20:51-07:00	[thread overview]
Message-ID: <795d1d54-0868-4745-8132-b38165494f39@googlegroups.com> (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

             reply	other threads:[~2018-06-02 15:20 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-02 15:20 gautier_niouzes [this message]
2018-06-02 15:55 ` Using interfaces 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
replies disabled

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