April 2, 2004

OT2004 : Delegation in Java

The session Delegation in Java - presented by Erik Groeneveld and Willem van den Ende was really interesting and thought-provoking - it's about "true delegation" rather than what most people these days think of as delegation (which should possibly be better called "forwarding"). True delegation is where methods can be delegated by one object to another but the receiver (i.e. this) stays bound to the object doing the delegating rather than the object being delegated to.
The consequences of this are that using delegation allows you to do things like multiple implementation inheritance and dynamic inheritance (changing what class an object "inherits" from at run time - very good for implementing the State Pattern).

The presenters have written an open source library for delegation in Java called Delegator which they introduced in this session, and we did some hands-on coding with it during the session. Unfortunately, "true delegation" in Java is rather difficult and doesn't come out very neatly, but it's an interesting concept to get your head around. If you want to try a language that does it really well, have a look at Self

Posted by ivan at April 2, 2004 4:47 PM
Copyright (c) 2004-2008 Ivan Moore
Comments

Sun have released a new version of Self this month. Apple Mac only, unfortunately, but they say it's designed for ease of porting.

Posted by: Nat Pryce at April 27, 2004 9:02 AM

Self also runs on Linux (see http://www.gliebe.de/self/) and Sun SPARC Solaris. Also see http://www.merlintec.com:8080/Self for info on Self.

Posted by: Ivan at May 4, 2004 8:52 AM