Browse thread
[Caml-list] Delegation based OO
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| 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 :
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