English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
[Caml-list] Delegation based OO
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2004-03-24 (00:45)
From: Kenneth Knowles <kknowles@b...>
Subject: Re: [Caml-list] Delegation based OO
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 :
    method b : int


# class x =
    method a = 3
    method b = self # a


# class y (del : delegate) =
    delegate del

    method a = "hello"


# 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


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