caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: John Prevost <j.prevost@cs.cmu.edu>
To: caml-list@inria.fr
Subject: Re: OCaml's OO design Re: [Caml-list] Protected methods
Date: 22 Jul 2002 00:20:18 -0400 (18.076 UMT)	[thread overview]
Message-ID: <86y9c4s8al.fsf@laurelin.dementia.org> (raw)
In-Reply-To: <20020722123732Z.garrigue@kurims.kyoto-u.ac.jp>

Just as a note, I think the major barrier to the "friend" behavior of
"protected" and "private" in Java (that is, methods of the appropriate
classes are able to call a given method even though other pieces of
code cannot see that it exists) is that subtyping and subclassing are
independent.

In Java, if you are handed a value of a given type and know that type
is a subclass of the "Foo" class, you *know* that it has all the
methods (hidden and not hidden) that a Foo has.  In O'Caml, this
luxury is not available.  If the object type of foo does not indicate
that a method "bar" exists, it may very well not exist.

This is why you need to do a song and dance with abstract types to
achieve the same effect.  The method *must* be visible or other
objects can't call it, since it is *only* the type of an object that
defines its interface.  Using type abstraction means that only code
that knows the underlying type has access, which allows you to show
that the method is there and has the right type, while not allowing
access to everybody.

Does this feel clunky?  Yes, a little bit.  But it's a price I'm
willing to pay for structural subtyping and self types.  I think it
calls to mind some of the subtler problems with subclassing and
subtyping--like invariants.  If you call a "protected" method in Java,
it generally means you're depending on the subclass to maintain
invariants from the superclass.  But all too often, this can lead to
problems where modularity breaks down.

Bondage programming?  Yeah, could be.  :) But it has some interesting
typing properties rarely found elsewhere, and makes us think about a
different set of implications in object calculi than most languages.
Consider learning to work within these constraints to be working in a
different programming paradigm than Java or C++ provides--because it
clearly is.  Different idioms are needed.  Some possibilities that
were closed off become open, and some that were open are now more
constrained.

It's, quite honestly, a load of fun.

John.
-------------------
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-22  4:13 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
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 [this message]
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=86y9c4s8al.fsf@laurelin.dementia.org \
    --to=j.prevost@cs.cmu.edu \
    --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).