comp.lang.ada
 help / color / mirror / Atom feed
From: Katarina Olsson <katolsster@gmail.com>
Subject: Dynamic binding
Date: Fri, 13 Apr 2012 13:13:17 -0700 (PDT)
Date: 2012-04-13T13:13:17-07:00	[thread overview]
Message-ID: <32a3d08f-7b48-46e2-b8cf-004acb6e40a3@d4g2000vbn.googlegroups.com> (raw)

Hello,
I have a question about dispatching in Ada. As we know, methods in
java are always called on their objects. Let say that we have a class
Parent with methods a() and b(), where a calls b like this:

class Parent{

public void a() {
System.out.println("parent a");
b();
}

public void b(){
System.out.println("parent b");
}
}

Consider now the class Child extends Parent. It has overridden the b()
method like this:

class Child extends Parent{

@Override
public void b(){
System.out.println("child b");
}

}

When creating a Child object and calling the a() method,

Child c = new Child();
c.a();

the output will be the following on stdout:

>>parent a
>>child b

I have now attempted to reproduce the corresponding case in Ada. If I
create a tagged record Object in package Parent, and then the
corresponding procedures (or functions):

procedure A (This : access all Object);
procedure B (This : access all Object);

and then in package Child, I create a new Parent.Object:

type Object is new Parent.Object with null record

...and override the B method:

overrides
procedure B (This : access all Object)

This should correspond to the previous java case, shouldn't it? In any
case it seems to me that calling the A procedure on the Child Object,
would render the output

>>parent a
>>parent b -- (instead of child b)

Do I need to try again or have I understood it correctly? And if I
have, how would I best reproduce the java behaviour?








             reply	other threads:[~2012-04-13 20:14 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-13 20:13 Katarina Olsson [this message]
2012-04-13 20:55 ` Dynamic binding Dmitry A. Kazakov
2012-04-14  6:41   ` Niklas Holsti
2012-04-14  7:39   ` Simon Wright
2012-04-14  8:58     ` Dmitry A. Kazakov
2012-04-15 12:04 ` AdaMagica
  -- strict thread matches above, loose matches on Subject: below --
2012-04-13 20:11 Katarina Olsson
2012-04-14  8:43 ` Georg Bauhaus
2012-04-14 17:17   ` Simon Wright
replies disabled

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