comp.lang.ada
 help / color / mirror / Atom feed
From: slos <new.stephane.los@gmail.com>
Subject: Re: Polymorphism
Date: Mon, 11 May 2015 15:05:55 -0700 (PDT)
Date: 2015-05-11T15:05:55-07:00	[thread overview]
Message-ID: <d0b830a1-19c8-462e-b1c8-a2b19e470674@googlegroups.com> (raw)
In-Reply-To: <migd9c$k9h$1@loke.gir.dk>

Le jeudi 7 mai 2015 21:09:33 UTC+2, Randy Brukardt a écrit :
> "Dmitry A. Kazakov"  wrote in message 
> news:...
> ...
> > I don't know why it is not allowed.
> 
> It *is* allowed. The problem in the OPs case is that the routine was 
> abstract. Abstract routines must be overridden, but if it is private a 
> client can't know that. Moreover, a client *cannot* override a private 
> operation, so there could be no client in that case. Thus the original 
> declaration is illegal.
> 
> As Simon pointed out, if the operation is concrete, it is fine to put it 
> there. Then all clients that need to override it have to be child packages. 
> Claw uses this extensively.
> 
> > Moreover, it probably would make sense
> > to move all declarations of overriding into private
> 
> This is my coding standard. I only put new stuff into the visible part.
> 
> > or even further into the package body
> 
> That's not allowed as the tag has to be known when the type is frozen (that 
> is, at the end of the specification). Of course, it would be possible to 
> have a different set of rules where the tag isn't known at that point, but 
> that's not the Ada design.
> 
> > because the fact of overriding is mere an implementation
> > detail, since the primitive subroutine is there anyway no matter what.
> 
> Correct; that's why I put them into the private part.
> 
>                                Randy.

Thank you Randy for your detailed information.

I have corrected my code according to the suggestions found here but I still think that there is maybe something to improve here.

If I remember correctly, I should have verified before posting but it's already late, in C++ one can have protected members which can be used by friends.
I can't see in Ada such thing like protected stuff and friends. Maybe there is ?

Indeed I was looking for something like that.

The client of my root class do not need to have access to those helping methods that have to be implemented by the derived ones.

I am quite happy with the child package solution exposed here by Simon but then that has disturbed my packages hierarchy... ;-)

I had grouped my derived classes by field bus technology, one package for PROFIBUS, another for EtherCAT and so on.

Since the root class, implementing an acyclic request, is independent on the field bus technology, I had had a "with" clause to my derived requests and it was working fine, excepted that my abstract methods had to be public.

So it ends up with two related hierarchies, one descending from the root acyclic request and the derived requests grouped by technology, and another hierarchy holding types, constants, etc... that can be useful also for other stuff like status, indications...

But again, I am fine with that solution if there is no smarter way.

BR,
Stéphane
http://slo-ist.fr/ada4autom


  reply	other threads:[~2015-05-11 22:05 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-06 23:05 Polymorphism slos
2015-05-07  7:28 ` Polymorphism Simon Wright
2015-05-07  8:32   ` Polymorphism slos
2015-05-07  7:41 ` Polymorphism Dmitry A. Kazakov
2015-05-07  8:34   ` Polymorphism slos
2015-05-07 19:09   ` Polymorphism Randy Brukardt
2015-05-11 22:05     ` slos [this message]
2015-05-12  1:29       ` Polymorphism Randy Brukardt
2015-05-14 21:34         ` Polymorphism slos
  -- strict thread matches above, loose matches on Subject: below --
1996-11-25  0:00 polymorphism W. Wesley Groleau (Wes)
replies disabled

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