comp.lang.ada
 help / color / mirror / Atom feed
* OO: How to?  Writeable from a readable?
@ 2003-01-05 23:09 chris.danx
  2003-01-05 23:40 ` tmoran
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: chris.danx @ 2003-01-05 23:09 UTC (permalink / raw)


Hi,

How can you resolve the following problem?  Let's suppose you have a 
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 
this problem (I want to allow a writeable wherever a readable is allowed!)?


Cheers,
Danx
-- 
for personal replies change spamoff to chris




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: OO: How to?  Writeable from a readable?
  2003-01-05 23:09 OO: How to? Writeable from a readable? chris.danx
@ 2003-01-05 23:40 ` tmoran
  2003-01-06  3:39 ` John R. Strohm
  2003-01-06 18:00 ` OO: " Stephen Leake
  2 siblings, 0 replies; 5+ messages in thread
From: tmoran @ 2003-01-05 23:40 UTC (permalink / raw)


> 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;



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How to?  Writeable from a readable?
  2003-01-05 23:09 OO: How to? Writeable from a readable? chris.danx
  2003-01-05 23:40 ` tmoran
@ 2003-01-06  3:39 ` John R. Strohm
  2003-01-06  9:25   ` chris.danx
  2003-01-06 18:00 ` OO: " Stephen Leake
  2 siblings, 1 reply; 5+ messages in thread
From: John R. Strohm @ 2003-01-06  3:39 UTC (permalink / raw)


Maybe I'm way out in left field here.

In capability-based operating system terms, it sounds as though you are
trying to take a read-only capability and amplify it into a read-write
capability.  Every capability system I ever saw was specifically designed to
prevent you from doing precisely that: if the owner of the object wanted you
to have read-write access to the, he would have granted you a read-write
capability for the object in the first place.

What I think you want to do is go back to the original system, structure it
as a read-write object, and then make a read-only view of it that you give
out to the world.  Only the ones who really have a legitimate need for
read-write access get the read-write capability.

"chris.danx" <spamoff.danx@ntlworld.com> wrote in message
news:3T2S9.721$GU4.33144@newsfep1-gui.server.ntli.net...
> Hi,
>
> How can you resolve the following problem?  Let's suppose you have a
> 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
> this problem (I want to allow a writeable wherever a readable is
allowed!)?
>
>
> Cheers,
> Danx
> --
> for personal replies change spamoff to chris
>





^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How to?  Writeable from a readable?
  2003-01-06  3:39 ` John R. Strohm
@ 2003-01-06  9:25   ` chris.danx
  0 siblings, 0 replies; 5+ messages in thread
From: chris.danx @ 2003-01-06  9:25 UTC (permalink / raw)


John R. Strohm wrote:
> Maybe I'm way out in left field here.
> 
> In capability-based operating system terms, it sounds as though you are
> trying to take a read-only capability and amplify it into a read-write
> capability.  Every capability system I ever saw was specifically designed to
> prevent you from doing precisely that: if the owner of the object wanted you
> to have read-write access to the, he would have granted you a read-write
> capability for the object in the first place.
> 
> What I think you want to do is go back to the original system, structure it
> as a read-write object, and then make a read-only view of it that you give
> out to the world.  Only the ones who really have a legitimate need for
> read-write access get the read-write capability.

That was my first idea, but since it will be OO the read only view of 
the data would inherit the operations of the read-write view and so the 
client would be able to modify the read-only raster - unless the 
operations where overridden to throw an exception, but I'd think that'd 
be a bad design choice in this instance.

What I'm considering is

Raster is abstract tagged ...;

Read_Only_Raster is new Raster with tagged ...;

Write_Read_Raster is new Raster with tagged ...;

That would enable the client to use a read_only_raster or 
write_read_raster wherever they could use a raster.


Chris
-- 
for personal replies change spamoff to chris




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: OO: How to?  Writeable from a readable?
  2003-01-05 23:09 OO: How to? Writeable from a readable? chris.danx
  2003-01-05 23:40 ` tmoran
  2003-01-06  3:39 ` John R. Strohm
@ 2003-01-06 18:00 ` Stephen Leake
  2 siblings, 0 replies; 5+ messages in thread
From: Stephen Leake @ 2003-01-06 18:00 UTC (permalink / raw)


"chris.danx" <spamoff.danx@ntlworld.com> writes:

> 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, 

Yes you can, in a child package.

-- 
-- Stephe



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2003-01-06 18:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-01-05 23:09 OO: How to? Writeable from a readable? chris.danx
2003-01-05 23:40 ` tmoran
2003-01-06  3:39 ` John R. Strohm
2003-01-06  9:25   ` chris.danx
2003-01-06 18:00 ` OO: " Stephen Leake

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