comp.lang.ada
 help / color / mirror / Atom feed
From: "Matthew Heaney" <matthew_heaney@acm.org>
Subject: Re: tagged types extensions - language design question
Date: 2000/01/31
Date: 2000-01-31T00:00:00+00:00	[thread overview]
Message-ID: <NCfl4.1353$gC3.64742@newsread1.prod.itd.earthlink.net> (raw)
In-Reply-To: s9av7kh45io46@corp.supernews.com

In article <s9av7kh45io46@corp.supernews.com> , "Vladimir Olensky" 
<vladimir_olensky@yahoo.com> wrote:

> Yes, as a matter of fact  this is not a big deal.
> Actually everything needed could be declared  in one package.
> One need just to remember the right sequence - first to declare
> abstract public extension of the root type, then it's abstract private
> extension and then concrete final extensions (in my case two of them).

Yes, you have to declare the public part of abstraction first.

> Very similar to the case when one wants to declare deallocation
> procedure for some private type in the same package where this
> private type is declared. Here right sequence is also very important
> and might be even less obvious for those who encounter that need
> for the first time.

If you have a "by-reference" abstraction, that is, an abstraction
designated by a pointer, then there's an idiom for that too.

(You need to put objects on the heap when you have "containment by
reference," instead of "containment by value," as is often the case when
doing class-wide programming.)

Basically, you declare the type as limited and indefinite, and declare
all primitive operations with access parameters:

package P is

  type T (<>) is abstract tagged limited private;

  type T_Access is access all T'Class;
  for T_Access'Storage_Size use 0;

  procedure Op (O : access T);
...
end P;

Non-abstract types in the class declare a constructor for the type:

package P.C is

  type NT is new T with private;

  function New_NT return T_Access;  -- possibly NT_Access

  procedure Op (O : access NT);
...
end P.C;


That all types in the class are limited and indefinite prevents clients
from declaring their own instances directly.  You want to force them to
use your constructor.

In general, a client should never invoke an allocator ("new T")
directly.  Give them a constructor, and invoke the allocator internally.

The other issue is how to reclaim instances.  You can either provide:

1) a classwide Free operation (declared in the root package, and
implemented by calling an instantiation of Unchecked_Deallocation, or by
calling a private dispatching deconstructor)

2) instead of using an access type, use a smart pointer, and let
deallocation be automatically


Both of these techniques are in the patterns archive (which I'm about to
do some maintenance of).

<http://www.acm.org/archives/patterns.html>




  reply	other threads:[~2000-01-31  0:00 UTC|newest]

Thread overview: 80+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-01-27  0:00 tagged types extensions - language design question Vladimir Olensky
2000-01-27  0:00 ` Matthew Heaney
2000-01-27  0:00   ` Charles Hixson
2000-01-28  0:00   ` Vladimir Olensky
2000-01-28  0:00     ` Matthew Heaney
2000-01-28  0:00       ` Charles Hixson
2000-01-28  0:00         ` Matthew Heaney
2000-02-01  0:00           ` Charles Hixson
2000-02-01  0:00             ` Matthew Heaney
2000-01-29  0:00       ` Vladimir Olensky
2000-01-29  0:00         ` Matthew Heaney
2000-01-31  0:00           ` Vladimir Olensky
2000-01-31  0:00             ` Matthew Heaney [this message]
2000-01-31  0:00               ` Vladimir Olensky
2000-01-29  0:00         ` Matthew Heaney
2000-01-27  0:00 ` Laurent Guerby
2000-01-28  0:00   ` Vladimir Olensky
2000-01-28  0:00     ` Andy
2000-01-28  0:00       ` Vladimir Olensky
2000-01-29  0:00         ` Andy
2000-01-31  0:00           ` Vladimir Olensky
2000-01-27  0:00 ` Fraser
2000-01-28  0:00 ` Tucker Taft
2000-01-31  0:00   ` Vladimir Olensky
2000-02-01  0:00   ` Charles Hixson
2000-02-01  0:00     ` Matthew Heaney
2000-02-01  0:00       ` Brian Rogoff
2000-02-03  0:00         ` scripting/extension language for Ada (was : Re: tagged types extensions) root
2000-02-03  0:00           ` Brian Rogoff
2000-02-04  0:00             ` Ray Blaak
2000-02-04  0:00               ` Stanley R. Allen
2000-02-04  0:00                 ` Samuel T. Harris
2000-02-05  0:00                   ` Lionel Draghi
2000-02-05  0:00                     ` Samuel T. Harris
2000-02-06  0:00                       ` Lionel Draghi
2000-02-06  0:00                       ` Bryce Bardin
2000-02-08  0:00                         ` Samuel T. Harris
2000-02-05  0:00                 ` Ray Blaak
2000-02-05  0:00                 ` Lionel Draghi
2000-02-04  0:00               ` Robert A Duff
2000-02-05  0:00                 ` blaak
2000-02-05  0:00                   ` Brian Rogoff
2000-02-09  0:00                   ` Robert A Duff
2000-02-09  0:00                     ` Ted Dennison
2000-02-10  0:00                       ` Samuel T. Harris
2000-02-05  0:00                 ` Ehud Lamm
2000-02-10  0:00                 ` Pascal Martin
2000-02-10  0:00                   ` Ray Blaak
2000-02-11  0:00                     ` David Starner
2000-02-12  0:00                       ` blaak
2000-02-15  0:00                         ` Brian Rogoff
2000-02-12  0:00                       ` Pascal Martin
2000-02-11  0:00                     ` scripting/extension language for Ada (we have an opportunity here) Tarjei T. Jensen
2000-02-11  0:00                       ` Robert I. Eachus
2000-02-12  0:00                         ` Samuel T. Harris
2000-02-12  0:00                         ` blaak
2000-02-12  0:00                         ` Tarjei Tj�stheim Jensen
2000-02-12  0:00                           ` root
2000-02-12  0:00                           ` Samuel T. Harris
2000-02-14  0:00                             ` Robert A Duff
2000-02-15  0:00                               ` Samuel T. Harris
2000-02-16  0:00                                 ` Robert A Duff
2000-02-16  0:00                                   ` Samuel T. Harris
2000-02-16  0:00                                     ` Robert A Duff
2000-02-17  0:00                                       ` Samuel T. Harris
2000-02-12  0:00                         ` Pascal Martin
2000-02-13  0:00                           ` Robert I. Eachus
2000-02-16  0:00                             ` scripting/extension ... [off topic] Nick Roberts
2000-02-16  0:00                               ` Ray Blaak
2000-02-14  0:00                     ` scripting/extension language for Ada (was : Re: tagged types extensions) Robert A Duff
2000-02-05  0:00             ` scripting/extension language for Ada (was : Re: tagged typesextensions) Lionel Draghi
2000-02-05  0:00           ` scripting/extension language for Ada (was : Re: tagged types extensions) Ehud Lamm
2000-02-06  0:00             ` Lionel Draghi
2000-02-06  0:00               ` scripting/extension language for Ada Terry Westley
2000-02-06  0:00               ` scripting/extension language for Ada (was : Re: tagged types extensions) Ehud Lamm
2000-02-09  0:00               ` Robert A Duff
2000-01-31  0:00 ` tagged types extensions - language design question Mark Lundquist
2000-02-01  0:00   ` Simon Wright
2000-02-01  0:00   ` Vladimir Olensky
2000-02-01  0:00   ` Ehud Lamm
replies disabled

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