Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!

Idiom #90 Read-only outside

Expose a read-only integer x to the outside world while being writable inside a structure or a class Foo.

struct Foo
{
    private int _x;
    int x() {return _x;}
}

if the result is an aggregate, then type can be quailified const and the transitiveness will make all the sub-members read-only
package Foos is
      
   type Foo is private;
      
   function X (Self : Foo) return Integer;
      
private
   type Foo is
      record
         X : Integer;
      end record;
      
end Foos;
   
package body Foos is
      
   function X (Self : Foo) return Integer is (Self.X);
      
end Foos;

New implementation...
< >
bbtemp