comp.lang.ada
 help / color / mirror / Atom feed
From: "Matthew Heaney" <matthew_heaney@acm.org>
Subject: Re: how do i include 111111 in an enumaration type ?
Date: 1999/10/13
Date: 1999-10-13T00:00:00+00:00	[thread overview]
Message-ID: <380485d2_1@news1.prserv.net> (raw)
In-Reply-To: slrn808j1s.o7.lutz@taranis.iks-jena.de

In article <slrn808j1s.o7.lutz@taranis.iks-jena.de> , lutz@iks-jena.de 
(Lutz Donnerhacke) wrote:

> From reading the Rationale and Reference Manual, the novice (like me) can
> not deduce, that this 'Unchecked_'-Package is required for normal usage.

Unchecked_Deallocation is not required for normal usage.

There are idioms for implementing abstractions that use the heap or some
form of indirection.  Basically, you want to hide all of that from the
client.

The type Unbounded_String is a good example of an abstraction that
internally uses heap, but hides this fact from the client.  This is how
a well-designed abstraction should be: it should hide information.

The problem is that many programmers come from a C or otherwise
non-object oriented background, and use raw pointers (really, heap
allocation) in the public part of the abstraction.  This is wrong.

The idiom for class-wide programming (in which indirection is necessary,
because a class-wide type is indefinite) is to declare the root type as
limited and indefinite, and let each specific type in the class export
its own constructor:

  package P is

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

    type Root_T_Access is access all Root_T;

    <ops>

    Free (O : in out Root_T_Access);
  ...
  end P;

  package P.C is

    type T is new Root_T with private;

    function New_T return Root_T_Access;

    <override ops>
  ...
  end P.C;


A client *never* calls "new" directly; he always goes through a
constructor.

In the example above, the client does however have to call a
deconstructor (Free) directly.  The deconstructor is implemented by
dispatching on a private primitive operation that returns the object to
the storage pool for the specific type.

Realize of course that indirection is not always required.  In the
observer pattern, for example, both object and subject are allocated
statically, without any heap or pointer use.


> Instead the longish discussions about accessibility rules lead me to the
> belief, that access types are like smart pointers.

It is possible to implement a smart pointer yourself, so that you don't
have to call Free manually.  See the smart pointer article in the design
patterns archive.

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

For other smart pointer examples, just search for "handle" or "do_free".

Matt

--
The new standards [for science curricula in Kansas] do not forbid the
teaching of evolution, but the subject will no longer be included in
statewide tests for evaluating students--a virtual guarantee, given the
realities of education, that this central concept of biology will be
diluted or eliminated, thus reducing courses to something like chemistry
without the periodic table, or American history without Lincoln.

Stephen Jay Gould, Time, 23 Aug 1999




  reply	other threads:[~1999-10-13  0:00 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <7tsq3o$92p$1@minus.oleane.net>
     [not found] ` <38021792_4@news1.prserv.net>
     [not found]   ` <slrn80495c.2a2.aidan@skinner.demon.co.uk>
1999-10-11  0:00     ` how do i include 111111 in an enumaration type ? Keith Thompson
1999-10-12  0:00   ` Sybs ALHABSHI
1999-10-12  0:00     ` Lutz Donnerhacke
1999-10-12  0:00       ` Matthew Heaney
1999-10-12  0:00         ` Lutz Donnerhacke
1999-10-12  0:00           ` Ted Dennison
1999-10-13  0:00             ` Lutz Donnerhacke
1999-10-13  0:00               ` Matthew Heaney [this message]
1999-10-13  0:00                 ` Ted Dennison
1999-10-12  0:00           ` Ted Dennison
1999-10-12  0:00     ` Matthew Heaney
1999-10-12  0:00       ` Ehud Lamm
1999-10-12  0:00 ` Nick Roberts
1999-10-14  0:00   ` Sybs ALHABSHI
replies disabled

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