comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: 'Protected' abstract subprograms
Date: Sat, 11 Jan 2014 09:59:11 +0100
Date: 2014-01-11T09:59:11+01:00	[thread overview]
Message-ID: <zlias3msw59.e73qre8brldl$.dlg@40tude.net> (raw)
In-Reply-To: 839fee13-2743-49f6-a7f3-f95578386201@googlegroups.com

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

  parent reply	other threads:[~2014-01-11  8:59 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-10 22:00 'Protected' abstract subprograms sbelmont700
2014-01-10 22:30 ` Randy Brukardt
2014-01-11 16:12   ` sbelmont700
2014-01-14  3:45     ` Randy Brukardt
2014-01-14  9:05       ` Dmitry A. Kazakov
2014-01-15  0:36         ` Randy Brukardt
2014-01-15  9:17           ` Dmitry A. Kazakov
2014-01-15 14:11             ` Robert A Duff
2014-01-15 15:40               ` adambeneschan
2014-01-15 21:21                 ` Robert A Duff
2014-01-15 23:10                   ` Randy Brukardt
2014-01-16  0:51                     ` Robert A Duff
2014-01-16 10:43                       ` AdaMagica
2014-01-16 16:32                         ` adambeneschan
2014-01-17  1:49                         ` Robert A Duff
2014-01-17 23:23                           ` Randy Brukardt
2014-01-19 21:07                             ` Robert A Duff
2014-01-20  8:40                               ` Dmitry A. Kazakov
2014-01-21 14:37                                 ` Robert A Duff
2014-01-22  8:27                                   ` Dmitry A. Kazakov
2014-01-21  1:21                               ` Randy Brukardt
2014-01-21 14:35                                 ` Robert A Duff
2014-01-15 23:17               ` Randy Brukardt
2014-01-16  8:52               ` Dmitry A. Kazakov
2014-01-11  8:41 ` J-P. Rosen
2014-01-11  8:59 ` Dmitry A. Kazakov [this message]
2014-01-11 13:42   ` Niklas Holsti
2014-01-11 19:35     ` Dmitry A. Kazakov
2014-01-12  9:19       ` Niklas Holsti
2014-01-12 10:22         ` Dmitry A. Kazakov
replies disabled

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