English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

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: 2005-12-08 (21:17)
From: Virgile Prevosto <virgile.prevosto@g...>
Subject: Re: [Caml-list] accessing values of a class from another instance

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

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