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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: 'Protected' abstract subprograms Date: Sat, 11 Jan 2014 09:59:11 +0100 Organization: cbb software GmbH Message-ID: References: <839fee13-2743-49f6-a7f3-f95578386201@googlegroups.com> Reply-To: mailbox@dmitry-kazakov.de NNTP-Posting-Host: SACMYH1Y5pIOuwuZn7n4NQ.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: 40tude_Dialog/2.0.15.1 X-Notice: Filtered by postfilter v. 0.8.2 Xref: news.eternal-september.org comp.lang.ada:18151 Date: 2014-01-11T09:59:11+01:00 List-Id: On Fri, 10 Jan 2014 14:00:31 -0800 (PST), sbelmont700@gmail.com wrote: > I find it to be a fairly common occurrence and, depending on who you ask, > a programming best practice to have a publically visible non-abstract > dispatching operation re-dispatch to an abstract subprogram (i.e. the > 'template pattern'). Fortunately, in Ada you don't need to re-dispatch because Ada directly supports composing operations out of primitive operations. That is what class-wide operations are for. type T is abstract ...; procedure Bar (X : T) is abstract; -- Primitive operation procedure Foo (X : T'Class); -- Class-wide operation procedure Foo (X : T'Class) is begin ... Bar (X); -- This dispatches ... end Foo; > In any case, does anyone know of a workaround to achieve the same sort of > behavior? First, and foremost, never re-dispatch, that is semantically broken [*], potentially unmaintainable (due to substitutability hell) and inefficient too. Secondly. There is another method of hiding operations. You pack it into a set of implementation packages. The packages declare the operation public, but the type itself is from some ancestor without the operation: type T is new Public_View with private; private type T is new Implementation_View with ...; The user of T does not know about Implementation_View, which itself is public of course. The drawback of this model is construction of new objects derived from T. But since that is completely broken in Ada, anyway, I mean the mess of limited aggregates, constructing functions etc, you will have fight that in any case. --------- * When you dispatch in a body of an operation that means that the body is valid for more than one type. Many types = class. Operation for all class = class-wide operation. It cannot be primitive, per definition. Re-dispatch breaks this model and effectively makes your design un/weakly typed. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de