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: | Alex Baretta <alex@b...> |
| Subject: | Re: [Caml-list] Delegation based OO |
Kenneth Knowles wrote: > On Wed, Mar 24, 2004 at 08:43:00AM +0900, Yamagata Yoriyuki wrote: > 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;; > Delegation is no relative of inheritance. Inheritance is a syntactic property (essentially classes inherit code), whereas delegation is a semantic property: once one method is delegated by a proxy object to an executor object, the the visibility of the proxy is lost. The method is executed as if it were invoked directly on the executor. As far as I'm concerned delegation serves specifically to implement efficiently (loc-wise) the proxy object pattern. Consider a DB access library where you define classes to access different DBMSs. The proxy object is backend neutral and dispatches depending on a configuration string or equivalent data structure. This can be done now, but each method in the proxy must be delegated explicitly to the backend object. Delegation passes control from the proxy to the backend in one line of code. Alex ------------------- 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