Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] prevent more than one object
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Mirko Aigner <Mirko.Aigner@a...>
Subject: [Caml-list] prevent more than one object
Hi !

I'm looking for a way to prevent that from a class more than one object 
is builded. Therefor I wrote this little files

(*singleton.ml*)
class singleton x =
   object
     val mutable data : int = x;
     method get_data = data;
     method set_data newdata = data <- newdata;
   end;;

let instance = new singleton 0

let get_instance = instance

(*singleton.mli*)
class singleton :
   int ->
   object
     method get_data : int
     method set_data : int -> unit
   end;;

val get_instance : singleton

The problem is the class is still public and instances can be build, any 
way to prevent this ?!

thx for helping
Mirko Aigner

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners