From: Alessandro Baretta <alex@baretta.com>
To: Jacques Garrigue <garrigue@kurims.kyoto-u.ac.jp>,
Ocaml <caml-list@inria.fr>
Subject: Re: [Caml-list] Protected methods
Date: Sat, 20 Jul 2002 09:41:32 +0200 [thread overview]
Message-ID: <3D39142C.4000404@baretta.com> (raw)
In-Reply-To: <20000720094622J.garrigue@kurims.kyoto-u.ac.jp>
Jacques Garrigue wrote:
>
> Actually, this is just an alternative model for protection:
> give all your clients the key, and don't give it to other people.
> This makes sense. The key can be a dummy only because the type system
> guarantees that you cannot forge its type.
> The problem with a "protected" keyword is that it should be given a
> semantics. Since an object type is structural (does not belong to a
> specific module), this is unclear how you can define where a protected
> method should be accessible.
I would be happy enough if protected methods were accessible
to other instances of the same class. This would be easy to
implement in O'Caml's type system, because the only place
where protected methods are visible is between the "object"
and "end" keywords. Nowhere else would the type system need
to account for the presence of protected keywords.
class a = object private method m = let x = new a in x # m end
> In practice, I probably won't do it that way, but this would require a
> deeper knowledge of your problem.
> For instance, if you want to show an internal state to a limited
> number of clients, you can just have a method returning this state
> with an abstract type. That's certainly more natural.
I fully agree. But what do you do when an instance of class
a holds other instances of class a which must collaborate
with the first in order to achieve the functionality of the
first? One possibility would be have define two classes: a
front-end, with only the methods which should be generally
available, and a backend, inheriting from the first and
adding those methods that are only meaningful for the
front-end. Otherwise, you define only one class and add a
protected keyword for these latter methods.
>>How about the following pseudocode? Is it sensible/viable?
>>
>>let module M : sig
>> class type public = object <public_methods> end
>> val make_public : unit -> public
>>end = struct
>> class type public = object <public_methods> end
>> class protectd =
>> object (self : #public)
>> <public_methods>
>> <protected_methods>
>> end
>> let make_public () -> (new protected :> public)
>>end
>>
>>If this a working alternative, I would prefer over both the
>>protector type and the protected keyword: clean, simple, and
>>idiomatic.
>
>
> This is both sensible and viable.
> The only weakness is that you won't be able to inherit from the public
> version of your class, since it is not a class but only a type.
> If you need to inherit, you should also export the protected version,
> and make sure that all your constructors apply a similar coercion to
> hide protected methods.
This is really all I need. At present, I do not perceive any
problem with inheritance, but then again, I might in the
future. At any rate, this is how I plan to modify the code I
am presently working on, so as to guarantee that the methods
I do not wish my object to export be kept private.
> This inheritance problem is the only reason I didn't suggest this
> approach first, but it is certainly simpler.
>
> Jacques Garrigue
Thank you very much for you interesting comments. I hope
that discussing such issues as this on the list might help
the Caml team improve its compiler and language.
Alex Baretta
-------------------
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
next prev parent reply other threads:[~2002-07-20 7:34 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
2002-07-19 10:01 ` Alessandro Baretta
2000-07-20 0:46 ` Jacques Garrigue
2002-07-20 7:41 ` Alessandro Baretta [this message]
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=3D39142C.4000404@baretta.com \
--to=alex@baretta.com \
--cc=caml-list@inria.fr \
--cc=garrigue@kurims.kyoto-u.ac.jp \
/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