From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id KAA28651; Fri, 19 Jul 2002 10:50:13 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id KAA28647 for ; Fri, 19 Jul 2002 10:50:12 +0200 (MET DST) Received: from kurims.kurims.kyoto-u.ac.jp (kurims.kurims.kyoto-u.ac.jp [130.54.16.1]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g6J8oA520841 for ; Fri, 19 Jul 2002 10:50:11 +0200 (MET DST) Received: from localhost (suiren.kurims.kyoto-u.ac.jp [130.54.16.25]) by kurims.kurims.kyoto-u.ac.jp (8.9.3/3.7W) with ESMTP id RAA03039; Fri, 19 Jul 2002 17:50:02 +0900 (JST) To: alex@baretta.com Cc: caml-list@inria.fr Subject: Re: [Caml-list] Protected methods In-Reply-To: <3D36AA1B.2090101@baretta.com> References: <3D369B89.1030000@baretta.com> <3D36A00A.7010807@gerd-stolpmann.de> <3D36AA1B.2090101@baretta.com> X-Mailer: Mew version 1.94.2 on Emacs 20.7 / Mule 4.0 (HANANOEN) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-Id: <20020719175002N.garrigue@kurims.kyoto-u.ac.jp> Date: Fri, 19 Jul 2002 17:50:02 +0900 From: Jacques Garrigue X-Dispatcher: imput version 20000228(IM140) Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk From: Alessandro Baretta > Gerd Stolpmann wrote: > > No, you cannot restrict the type of classes by signatures. > > The only way I know to protect a method is to define an opaque > > type that is hidden by the signature, e.g. > > > > sample.ml: > > > > type protector = unit > > > > class a = > > object > > method m () = ... > > ... > > end > > > > sample.mli: > > > > type protector > > > > class a : > > object > > method m : protector -> XXX > > ... > > end > > > > You cannot call m from other modules because you cannot create values > > for the type "protector". > > > > Gerd > > Effective, definitely, but practical? Is this not supposed > to be a feature of any general purpose object oriented language? Actually, this seems perfectly practical. If you have some good reason to "protect" a method, you can do it cleanly. By the way, ocaml is not a general purpose object-oriented languages, but a general purpose functional language with object-oriented features. In particular, encapsulation is supported by the module system rather than the class system. Even in object-oriented languages, I've seen heated discussions on whether using friend classes was good style or not. > Anyway, for the meantime I'll keep the method public, and > make sure I don't use it anywhere except where it makes > sense, and I'll wait for some more insight from the developers. Note that in many cases there are other ways to obtain the expected behaviour. For instance, if only one specific object is supposed to use a method, you might register a private callback with it rather than the other way round. Jacques Garrigue ------------------- 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