comp.lang.ada
 help / color / mirror / Atom feed
* Dynamic binding
@ 2012-04-13 20:13 Katarina Olsson
  2012-04-13 20:55 ` Dmitry A. Kazakov
  2012-04-15 12:04 ` AdaMagica
  0 siblings, 2 replies; 9+ messages in thread
From: Katarina Olsson @ 2012-04-13 20:13 UTC (permalink / 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?








^ permalink raw reply	[flat|nested] 9+ messages in thread
* Dynamic binding
@ 2012-04-13 20:11 Katarina Olsson
  2012-04-14  8:43 ` Georg Bauhaus
  0 siblings, 1 reply; 9+ messages in thread
From: Katarina Olsson @ 2012-04-13 20:11 UTC (permalink / 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?








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

end of thread, other threads:[~2012-04-15 12:04 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-13 20:13 Dynamic binding Katarina Olsson
2012-04-13 20:55 ` 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

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