I would like to suggest that the extension of a class/interface be a
first class construct in Groovy. The methods that are added to JDK
classes should use a language defined construct, which can also be used
by any user class. This allows a programmer using a binary library to
add methods to make the library classes polymorphic with custom
classes. I am new to Groovy and from what I have read, the extensions
are currently performed by use of a meta model object that performs
dispatching, so it sounds like the mechanism is there. I am asking for
the mechanism to be accessible from the language level, not just the
library level. The Objective-C language has this construct, and it has
proven to be quite useful. In that context an extension is not able to
access any private parts of the class being extended. This would be
required in Groovy to prevent security breaches, and because you are
really not changing the .class file of the extended class.
Michael Latta
|