Logo

Programming-Idioms

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

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.

class Foo{
  int _x = 0;
  int get x => _x;  
}
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