Interface specification in Ada

This is a discussion on Interface specification in Ada within the ADA forums in Programming Languages category; Hi, my preferred programming language is Java and I'm used to declare in an interface some common methods, that all subclasses have to implement. For example: interface Bicycle { void changeCadence(int newValue); void changeGear(int newValue); void speedUp(int increment); void applyBrakes(int decrement); } class RacingBicycle implements Bicycle { // remainder of this class implemented as before } If I accidentially implement RacingBicycle without providing the four methods mentioned above, the compiler would draw attention to this situation. In Ada, i found the keyword "interface" only in the context of multiple inheritance. The usage would be: package Bicycle is type Object is ...

Go Back   Application Development Forum > Programming Languages > ADA

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 06-11-2008, 08:46 AM
Dennis Hoppe
Guest
 
Default Interface specification in Ada

Hi,

my preferred programming language is Java and I'm used to declare in an
interface some common methods, that all subclasses have to implement.
For example:

interface Bicycle {
void changeCadence(int newValue);
void changeGear(int newValue);
void speedUp(int increment);
void applyBrakes(int decrement);
}

class RacingBicycle implements Bicycle {
// remainder of this class implemented as before
}

If I accidentially implement RacingBicycle without providing the four
methods mentioned above, the compiler would draw attention to this
situation.

In Ada, i found the keyword "interface" only in the context of multiple
inheritance. The usage would be:

package Bicycle is
type Object is interface;

procedure changeCadence (newValue : in Integer) is abstract;
procedure changeGear (newValue : in Integer) is abstract;
procedure speedUp (increment : in Integer) is abstract;
procedure applyBrakes (decrement : in Integer) is abstract;
end Bicycle;


with Bicycle;

package RacingBicycle is

type Object is new Bicycle.Object with null record;

-- omitted needed procedures to raise an error
end RacingBicycle;


Unfortunately, the build process runs through without any errors. In
this case, I want the compiler to notify me about missing procedure
implementations, because they are declared abstract in the interface.

I think, I missed something in the hierarchy, but I don't see it.


Thank you in advance,
Dennis Hoppe
Reply With Quote
  #2  
Old 06-11-2008, 09:04 AM
christoph.grein@eurocopter.com
Guest
 
Default Re: Interface specification in Ada

You missed the "this" parameter, which is implicit in Java, but
explicit in Ada:

package Bicycle is
* type Object is interface;

* procedure changeCadence (Ob: in out Object; newValue : in Integer)
is abstract;

etc.
Reply With Quote
  #3  
Old 06-11-2008, 11:02 AM
Georg Bauhaus
Guest
 
Default Re: Interface specification in Ada

christoph.grein@eurocopter.com schrieb:
> You missed the "this" parameter, which is implicit in Java, but
> explicit in Ada:
>
> package Bicycle is
> type Object is interface;
>
> procedure changeCadence (Ob: in out Object; newValue : in Integer)
> is abstract;


And in Ada 2005 the "this" parameter can be suitably
named, and when used, it can be written just like in
Java,

Peugeot: Bicyle.Object;

Peugeot.changeCadence(27);

Incidentally, I'd suggest you consider defining distict integer
types that reflect gears etc. By doing so you can have the
compiler check that a cadence number is not inadvertently
used as a gear number. E.g.,

type Gear is range 1 .. 21;
....
procedure changeGear
(The_Bike: in out Object; newValue : in Gear) is abstract;

or

type Gear
(Front_Wheel: Wheel_Number;
Rear_Wheel: Wheel_Number)
is private;

and so on.
Reply With Quote
  #4  
Old 06-11-2008, 12:34 PM
Robert A Duff
Guest
 
Default Re: Interface specification in Ada

christoph.grein@eurocopter.com writes:

> You missed the "this" parameter, which is implicit in Java, but
> explicit in Ada:
>
> package Bicycle is
> * type Object is interface;
>
> * procedure changeCadence (Ob: in out Object; newValue : in Integer)
> is abstract;


Also, it's a good idea to use the "overriding" keyword.

- Bob
Reply With Quote
  #5  
Old 06-11-2008, 05:23 PM
Dennis Hoppe
Guest
 
Default Re: Interface specification in Ada

Hello Christoph, Georg and Robert,

thank you for your advices. Indeed Java relieves me of state "this".


christoph.grein@eurocopter.com wrote:
> You missed the "this" parameter, which is implicit in Java, but
> explicit in Ada:
>
> package Bicycle is
> type Object is interface;
>
> procedure changeCadence (Ob: in out Object; newValue : in Integer)
> is abstract;
>
> etc.

Reply With Quote
  #6  
Old 06-12-2008, 04:37 AM
Georg Bauhaus
Guest
 
Default Re: Interface specification in Ada

Dennis Hoppe wrote:

> Indeed Java relieves me of state "this".


When I started writing Java many years ago, I too thought that
like in the Java books, when I want to name an object's
component it is not neccessary to refer to the object.
So don't do that, leave out "this".
But now I find myself writing "this.a" and "this.b" all the
time, to make sure I can easily see what "a" actually stands
for: does it name a component or does it name a method parameter
or local variable? With "this" there is no question. There is
almost never a question in Ada because you always name the
object in some way.
Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 12:31 AM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.