comp.lang.ada
 help / color / mirror / Atom feed
From: claveman@grzorgenplatz.net (Charles H. Sampson)
Subject: Re: Private discrete type as index
Date: Sat, 11 Jan 2003 06:36:53 -0800
Date: 2003-01-11T06:36:53-08:00	[thread overview]
Message-ID: <1folzmn.po64991od5f02N%claveman@grzorgenplatz.net> (raw)
In-Reply-To: cRQT9.21756$F63.404030@news.xtra.co.nz

AG <ang@xtra.co.nz> wrote:

> "James S. Rogers" <jimmaureenrogers@worldnet.att.net> wrote in message
> news:TwPT9.105450$hK4.8563792@bgtnsc05-news.ops.worldnet.att.net...
> 
> > "AG" <ang@xtra.co.nz> wrote in message
> > > However, what if you want to let your clients know that
> > > that the structure is indeed an array and provide appropriate
> > > operations on the index but prevent them from directly
> > > manipulating it?
> 
> >
> > I am unclear what you mean by "providing appropriate operations"
> > without allowing direct manipulation. This sounds like an iterator to
> > me. Please describe what you have in mind instead.
> >
> 
> OK, here it is:
> 
> package test is
> 
> type X is new Integer; -- What I'd like here is "limited private" instead of
> "new integer"
> 
> type Test is array(X) of Boolean;
> 
> function "+"(Left: X) return X; -- Unary increment (however that may be
> implemented)
> 
> function "+"(Left:X; N: Integer) return X; -- Shift by N positions (does not
> equal N times other "+")
> 
> private
> 
> -- Defiinition of "X" here whatever it may be
> 
> end test;

     It looks like you have an ADT that you've chosen to implement as 
an array.  If that's true, the fact that you've chosen an array, 
rather than a linked list or something else, is an implementation 
decision and should be hidden in the package or its private part.

     I'm guessing that you want the user to know that you've used an 
array for the ease of access to its components.  Unfortunately, losing 
that ease of access is one of the prices you pay for the benefit of 
the abstraction (information hiding).  I don't think it would be 
onerous to the ADT's users to have to employ a "retrieve component" 
function and a "store component" procedure. 

> The code above compiles fine. Replacing "new Integer" with "limited private"
> does not.
> 
> But, if it did, it would allow the user of the package to do things like
> 10th position from
> 
> wherever the index is now and it would be the responsibility of the
> implementation
> 
> to know what/where it is. At the same time, the client package would have no
> clue
> 
> as to what the type is or be able to operate on it directly (only through
> any functions
> 
> provided by the package which was the whole point).

                                Charlie

-- 
     For an email response, my real user name is csampson and my ISP is
inetworld.net.



  parent reply	other threads:[~2003-01-11 14:36 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-01-11 21:42 Private discrete type as index AG
2003-01-11  2:34 ` James S. Rogers
2003-01-12  0:09   ` AG
2003-01-11  7:16     ` James S. Rogers
2003-01-12  5:47       ` AG
2003-01-11 12:22         ` Dmitry A. Kazakov
2003-01-11 14:36         ` Charles H. Sampson [this message]
2003-01-12 19:23 ` Keith Thompson
2003-01-12 19:48   ` tmoran
2003-01-15 16:45     ` Dmitry A. Kazakov
2003-01-18  6:24       ` AG
2003-01-17 14:14         ` tmoran
2003-01-19  1:38           ` AG
2003-01-18  8:36             ` tmoran
2003-01-19  6:06               ` AG
2003-01-17 16:28         ` 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