From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.66.153.173 with SMTP id vh13mr21726667pab.37.1431381955732; Mon, 11 May 2015 15:05:55 -0700 (PDT) X-Received: by 10.140.102.75 with SMTP id v69mr162212qge.19.1431381955473; Mon, 11 May 2015 15:05:55 -0700 (PDT) Path: border2.nntp.dca1.giganews.com!nntp.giganews.com!m20no2143554iga.0!news-out.google.com!t92ni322qga.1!nntp.google.com!j5no6732967qga.1!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Mon, 11 May 2015 15:05:55 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=80.119.168.244; posting-account=O3LyFwoAAACc1uh60ZcOUmAGdDmGsEcV NNTP-Posting-Host: 80.119.168.244 References: <5hbl45anxasb.1jn73i00zgy2i.dlg@40tude.net> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: Polymorphism From: slos Injection-Date: Mon, 11 May 2015 22:05:55 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Xref: number.nntp.giganews.com comp.lang.ada:193123 Date: 2015-05-11T15:05:55-07:00 List-Id: Le jeudi 7 mai 2015 21:09:33 UTC+2, Randy Brukardt a =E9crit=A0: > "Dmitry A. Kazakov" wrote in message=20 > news:... > ... > > I don't know why it is not allowed. >=20 > It *is* allowed. The problem in the OPs case is that the routine was=20 > abstract. Abstract routines must be overridden, but if it is private a=20 > client can't know that. Moreover, a client *cannot* override a private=20 > operation, so there could be no client in that case. Thus the original=20 > declaration is illegal. >=20 > As Simon pointed out, if the operation is concrete, it is fine to put it= =20 > there. Then all clients that need to override it have to be child package= s.=20 > Claw uses this extensively. >=20 > > Moreover, it probably would make sense > > to move all declarations of overriding into private >=20 > This is my coding standard. I only put new stuff into the visible part. >=20 > > or even further into the package body >=20 > That's not allowed as the tag has to be known when the type is frozen (th= at=20 > is, at the end of the specification). Of course, it would be possible to= =20 > have a different set of rules where the tag isn't known at that point, bu= t=20 > that's not the Ada design. >=20 > > because the fact of overriding is mere an implementation > > detail, since the primitive subroutine is there anyway no matter what. >=20 > Correct; that's why I put them into the private part. >=20 > Randy. Thank you Randy for your detailed information. I have corrected my code according to the suggestions found here but I stil= l think that there is maybe something to improve here. If I remember correctly, I should have verified before posting but it's alr= eady late, in C++ one can have protected members which can be used by frien= ds. 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 met= hods 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 P= ROFIBUS, another for EtherCAT and so on. Since the root class, implementing an acyclic request, is independent on th= e field bus technology, I had had a "with" clause to my derived requests an= d 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 ac= yclic request and the derived requests grouped by technology, and another h= ierarchy 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=E9phane http://slo-ist.fr/ada4autom