caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Kenneth Knowles <kknowles@berkeley.edu>
To: caml-list@inria.fr
Subject: Re: [Caml-list] Delegation based OO
Date: Tue, 23 Mar 2004 16:45:48 -0800	[thread overview]
Message-ID: <20040324004548.GA19738@tallman.kefka.frap.net> (raw)
In-Reply-To: <20040324.084300.18291498.yoriyuki@mbg.ocn.ne.jp>

On Wed, Mar 24, 2004 at 08:43:00AM +0900, Yamagata Yoriyuki wrote:
> There is a difference.  You cannot hide the method "y" in the class
> definition "x". An object can be coerced to a super type, so that it's
> type would forget about the method "y", then you override it...
> 
> --
> Yamagata Yoriyuki

Good point, I think.
Let's see if I understand; I think you mean the following imaginary situation:

# class type delegate :
  object
    method b : int
  end;;

...

# class x =
  object(self)
    method a = 3
    method b = self # a
  end;;

...

# class y (del : delegate) =
  object
    delegate del

    method a = "hello"
  end;;

...

# let foo = new x;;
val foo : <a : int; b : int>

# let bar = new y (x :> delegate)
val bar : <a : string; b : int>

This is solved by treating delegation as object composition, rather than
inheritance, making overriding irrelevant.  The original methods of "del" all
point to the same "self" object.

This also solves the use of delegating only a subset of methods, since only the
methods of the statically determined (or specified) type of "del" are delegated,
minus the methods defined by "x."

I'm not advocating adding this to the language, but it does seem pretty
straightforward.

Kenn

-------------------
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:[~2004-03-24  0:45 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-03-22 10:18 Alex Baretta
2004-03-22 23:01 ` Yamagata Yoriyuki
2004-03-23  0:29   ` Kenneth Knowles
2004-03-23 23:43     ` Yamagata Yoriyuki
2004-03-24  0:45       ` Kenneth Knowles [this message]
2004-03-24 10:43         ` Alex Baretta
2004-03-24 14:11           ` Yamagata Yoriyuki
2004-03-24 15:00             ` Alex Baretta
2004-03-24 16:57           ` Kenneth Knowles
2004-03-23  1:14 ` Jacques Garrigue
2004-03-23  7:27   ` Alex Baretta
2004-03-23  9:01   ` Stefano Zacchiroli
2004-03-23  9:41     ` Alex Baretta
2004-03-23  9:44     ` Jacques Garrigue
2004-03-23  9:47       ` Stefano Zacchiroli
2004-03-23  8:56 ` Correnson Loïc

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=20040324004548.GA19738@tallman.kefka.frap.net \
    --to=kknowles@berkeley.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).