Object-oriented methods in Ada
Having written Java code for a few decades, there are some facets that I find to be a βmustβ (without having any good reason for it). One such thing is the way object-orientation makes use of methods. So, while I now try to learn myself Ada (have some PL/SQL experience), I find myself searching for method declaration.
As everyone who has coded Java knows, a method is written as a function within the class declaration. When the method is called, it is called as something that belongs to the class (or rather the object).
Ex. A Java class C may have a method m(x, y, β¦). And object o of class C can then use this method through the call:
o.m(x, y, β¦)
Having search (or skimmed) through both literature and the net, it is my understanding that the closet we get in Ada is to have a procedure or a function, with the first argument being of the containing type, declared in the type declaration, and then calling that proc/func by passing a variable of that type as the parameter (sorry if I mess this up, I know what Iβm thinking, but putting it in writing is less clear). This would lead to a proc/func call similar to:
m(o, x, y, β¦)
Or have I missed something?
What is the βcorrectβ object oriented way of writing the following in Ada?
public class Hello
{
public void SayHello()
{
System.out.println( βHello World!β);
}
}
And similar upon use:
{
Hello greeting = new Hello();
greeting.SayHello();
}
Your help and patience are appreciated.
Roald
15 posts - 10 participants