caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@kurims.kyoto-u.ac.jp>
To: alex@baretta.com
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Protected methods
Date: Fri, 19 Jul 2002 17:50:02 +0900	[thread overview]
Message-ID: <20020719175002N.garrigue@kurims.kyoto-u.ac.jp> (raw)
In-Reply-To: <3D36AA1B.2090101@baretta.com>

From: Alessandro Baretta <alex@baretta.com>
> 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


  reply	other threads:[~2002-07-19  8:50 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-07-18 10:42 Alessandro Baretta
2002-07-18 11:01 ` Gerd Stolpmann
2002-07-18 11:44   ` Alessandro Baretta
2002-07-19  8:50     ` Jacques Garrigue [this message]
2002-07-19 10:01       ` Alessandro Baretta
2000-07-20  0:46         ` Jacques Garrigue
2002-07-20  7:41           ` Alessandro Baretta
2002-07-20  1:31         ` Jacques Garrigue
2002-07-20  7:48           ` Alessandro Baretta
2002-07-20 22:48 ` Dmitry Bely
2002-07-20 23:08   ` Brian Smith
2002-07-22  3:37     ` OCaml's OO design " Jacques Garrigue
2002-07-22  4:20       ` John Prevost
2002-07-20 23:54   ` Alessandro Baretta
2002-07-21  7:52     ` Dmitry Bely
2002-07-21 13:14       ` Alessandro Baretta

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20020719175002N.garrigue@kurims.kyoto-u.ac.jp \
    --to=garrigue@kurims.kyoto-u.ac.jp \
    --cc=alex@baretta.com \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).