On Sat, Jan 8, 2011 at 2:59 PM, Martin Makundi <martin.maku...@koodaripalvelut.com> wrote: > > It should be possible to say that "man will proxy by default all get > methods of his belongings", It should be possible to say that "bag > will proxy by default all get methods of his belongings". Same with > pencil casing. In such situation i wouldn't need to CODE all thsoe > get.get.get.get methods but the framework or compilation procedure > would provide them automatically. > > WHEN I want to intervene the GET method (and track borrowed pencils > for example) I could just override the man.getPencil explicitly to do > that. >
Okay, I see your point. This type of thing is possible in a language like Ruby where you can merely send "messages" to an object as opposed to calling methods. However, then you have to put all sorts of logic in the "handle any message" method to try to figure out what the heck you're trying to do (like ActiveRecord's dynamic finders). Is this any better than just writing a method like this in Java: public <T> T borrowObject(Class<T> objectType) where you can do Pencil p = man.borrowObject(Pencil.class); Either way, you have to put logic somewhere that tries to figure out what the heck you want to borrow and then figure out where the heck to get it. I don't necessarily think I would consider this a shortcoming of the Java language.