jastrachan | 12 Apr 12:18 2004
Picon

Re: DefaultGroovyMethods and intertype declarations (was: [IDEA] auto-type coercion thoughts)


On 7 Apr 2004, at 17:23, Jon Tirsen wrote:

> bing ran wrote:
>
>> I think it might be a good idea to refactor the DefaultGroovyMethod
>> class, which has become too bulky. I don't understand why we cannot
>>
>
> I'm not sure how the DefaultGroovyMethods class works, so forgive me 
> if I'm completely off track here. It's about adding the nifty methods 
> to the existing Java API, right?
>
> I think we should generalize this behaviour. In Ruby a class can be 
> defined in many different files and places and you can easily add or 
> change behaviour in existing classes. This is definitely an enabling 
> feature, if abused it's very dangerous, when used correctly it's very 
> powerful.
>
> I'm thinking about something like the AOP concept called inter-type 
> declarations. This makes it possible to introduce new fields and 
> methods to existing classes. You basically select a number of classes 
> based on some critera (for example each class implementing Collection) 
> and add a method to them (for example "each").
> The syntax is quite simple in AspectJ (and it's basically the same 
> syntax in Ruby):
> public void Collection.each(Closure closure) {
>    // iterate using iterator and call closure
> }
>
> What do you think?

Very interesting. It'd be great for folks to be able to write new 
methods in Groovy to make any J2EE API more groovy.

The next question is; how do we apply these new methods. I'm assuming 
we'll need some module-like mechanism like in Ruby? Where new methods 
are defined inside a 'module' and we 'use' the module to apply them?

James
-------
http://radio.weblogs.com/0112098/

Gmane