From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,bbd357da6d6d7756 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-01-05 15:40:07 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!nntp.cs.ubc.ca!nntp.itservices.ubc.ca!cyclone.bc.net!snoopy.risq.qc.ca!newshub.northeast.verio.net!verio!news-out.cwix.com!newsfeed.cwix.com!wn14feed!worldnet.att.net!204.127.198.204!attbi_feed4!attbi.com!sccrnsc01.POSTED!not-for-mail From: tmoran@acm.org Newsgroups: comp.lang.ada Subject: Re: OO: How to? Writeable from a readable? References: <3T2S9.721$GU4.33144@newsfep1-gui.server.ntli.net> X-Newsreader: Tom's custom newsreader Message-ID: NNTP-Posting-Host: 12.234.13.56 X-Complaints-To: abuse@attbi.com X-Trace: sccrnsc01 1041810006 12.234.13.56 (Sun, 05 Jan 2003 23:40:06 GMT) NNTP-Posting-Date: Sun, 05 Jan 2003 23:40:06 GMT Organization: AT&T Broadband Date: Sun, 05 Jan 2003 23:40:06 GMT Xref: archiver1.google.com comp.lang.ada:32586 Date: 2003-01-05T23:40:06+00:00 List-Id: > tagged type readable_x say, which only allows you read access to the > data in it, and you want to extend it with a new tagged type writeable_x > which allows you read and write access to data. How can you do this? > > The problem as I see it, is that if you make the data in readable_x > private you can't extend and modify it in the extended type, but if you > make it public anyone can modify the data anyway. Is there a way around The way (other than "constant") to make something read-only is to make it private and supply a function that reads it and returns its value. If you have a type which is private, and you want operations for another type (or any operations at all) to be able to see the private stuff, then those operations must be either in the same package's body (the simplest approach) or in a child package: package r is type readable is tagged private; function a_field(x : readable) return integer; function another_field(x : readable) return string; private type readable is tagged record a_field : integer; another_field : string(1 .. 10); end record; end r; package body r is function a_field(x : readable) return integer is begin return x.a_field;end a_field; function another_field(x : readable) return string is begin return x.another_field;end another_field; end r; package r.w is type writeable is new r.readable with record new_field : integer; end record; procedure fiddle(x : in out writeable); end r.w; package body r.w is procedure fiddle(x : in out writeable) is begin x.a_field := x.new_field; end fiddle; end r.w; with r, r.w; procedure testrw is x : r.w.writeable; begin for i in 1 .. r.w.a_field(x) loop r.w.fiddle(x); end loop; end testrw;