Version française
Home     About     Download     Resources     Contact us    
Browse thread
accessing values of a class from another instance
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Virgile Prevosto <virgile.prevosto@g...>
Subject: Re: [Caml-list] accessing values of a class from another instance
Hello,

2005/12/8, Shaddin Doghmi <shaddin@mitre.org>:
> It seems instance variables of an object are not accessible from other
> objects that are instances of the same class. What is a nice way to
> simulate this functionality? I would like to avoid accessor methods for

A possibility is to use the module system and let your instance
variable and the corresponding accessor method have an abstract type:
this way, you'll still be able to call the method outside of the
module, but you won't be able to use its result. This is described
here:
http://caml.inria.fr/pub/docs/manual-ocaml/manual005.html#ss:friends

Of course, one could probably think of more sophisticated interfaces
for the module, where you would for instance export only a class type
where the accessor method
itself is hidden and a constructor function that performs at the same
time a 'new' and a coercion to this class type. I've never played with
that, though.
--
E tutto per oggi, a la prossima volta
Virgile