comp.lang.ada
 help / color / mirror / Atom feed
From: "chris.danx" <spamoff.danx@ntlworld.com>
Subject: Re: Hiding a type
Date: Sun, 7 Jul 2002 00:10:45 +0100
Date: 2002-07-07T00:10:45+01:00	[thread overview]
Message-ID: <pOKV8.15189$xf3.2097028@news11-gui.server.ntli.net> (raw)
In-Reply-To: 3D2733F4.8010304@hotmail.com


"Ryan Tarpine" <rtarpine@hotmail.com> wrote in message
news:3D2733F4.8010304@hotmail.com...
> Pat Rogers wrote:
>
> > Do check out a textbook from the library -- it is worth the time -- or
> > take one of the on-line tutorials.  See www.adapower.com.
>
> I hope to get a textbook soon.  I'll have to buy one, as my local
> library is quite small.  I've read most of Ada Distilled and use it as a
> quick reference, and I don't find the reference manual too difficult to
> look through because I've used much more cumbersome languages before
> **ahem**c++**cough**.  The Lovelace tutorial is also wonderful.

Follow the links on adapower and you'll get a link to Ada 95:  the craft of
oo programming by John English.  It's the best textbook, but nowadays you'll
be lucky to get it in a nice bound book, as it has gone out of print
(saturation apparently), but there is an online version so it's not gone
completely and it's free for everyone!


> >>I want to write functions that will return something of type Hide in a
> >>way so clients can't do anything except pass it to other functions.  I
> >>also don't want them to know if I change how I implement it.  (In my
> >>real program, I'm trying to hide that Foo returns an access type.)
> >>Please tell how I should actually do this
> >
> >
> > package Opaque is
> >     type Hidden is limited private;
> >     -- declare the operations here that you want to export to clients
> > private
> >     type Hidden is access all Integer;
> > end Opaque;
>
> I'm sorry but I didn't make it clear enough.  It's more like this:
>
> package Test is
>      type Public_Name is limited private;
>      function Initialize( File_Name : String ) return Public_Name;
>      procedure Process( Input : Public_Name );
> private
>      type Private_Type is record ... end record;
>      type Private_Type_Ptr is access all Private_Type;
>      subtype Public_Name is Private_Type_Ptr; -- or what?
> end Test;
>
> I don't want to expose the name Private_Type_Ptr because I know that it
> might change in the future.  I know it sounds silly so it's probably
> just poor planning on my part.

Does that not do it? If it's right, it won't expose the private_type_ptr to
the world.  The name public_name will hide private_type_ptr.


> To give more specific details as to what I'm doing, I'm trying to return
> a pointer to a node in a tree structure.  There are several types of
> nodes and I'm concerned that in the future I will want to return a
> different type of node.  I want to hide this from the client.

Doesn't the client need to know what type of node they're dealing with in
order to process it?





  parent reply	other threads:[~2002-07-06 23:10 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-07-06 17:17 Hiding a type Ryan Tarpine
2002-07-06 21:30 ` Pat Rogers
2002-07-06 18:16   ` Ryan Tarpine
2002-07-06 22:49     ` sk
2002-07-06 22:52     ` Frank J. Lhota
2002-07-06 20:38       ` Ryan Tarpine
2002-07-07 10:31         ` Frank J. Lhota
2002-07-07 11:20       ` Simon Wright
2002-07-07 13:58         ` Frank J. Lhota
2002-07-07 22:24           ` Ryan Tarpine
2002-07-07 17:15         ` Jeffrey Carter
2002-07-07 17:58           ` Simon Wright
2002-07-06 23:10     ` chris.danx [this message]
2002-07-06 20:21       ` Ryan Tarpine
2002-07-07  1:58         ` Jeffrey Carter
2002-07-08  7:20         ` Preben Randhol
2002-07-06 23:12       ` chris.danx
replies disabled

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