logo       

Re: Extension as first class construct: msg#00116

lang.groovy.user

Subject: Re: Extension as first class construct

On Thu, Oct 14, 2004 at 08:16:48PM -0700, Michael Latta wrote:
> 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.
I think you are describing the 'use' Groovy JDK method...

SomeThirdPartyClass.use {
doSomeOfMyStuff()
}

> The Objective-C language has this construct, and it has
> proven to be quite useful.
To which specific syntax do you refer?

>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.

You can do this to instances, which has some of those features
for example adding a closure to an instance of Foo...
---
class Foo {
property bar
}
foo = new Foo()

m = { println bar }
m.delegate = foo
m.call()



Thanks

Jez.



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise