5 Jul 2005 10:45
Re: adding dependency injection to groovy (was Re: [groovy-user] grails: Groovy class loader and Spring)
Yeah; its kinda scary messing with 'new'. Though I was wondering if we only supported this kind of operation for abstract classes or interfaces; but maybe thats too confusing. Maybe a new keyword is cleaner... On 4 Jul 2005, at 13:47, Jeremy Rayner wrote: >> // lets create an instance of an interface... >> def f = new Cheese() >> >> which is pretty wacky - but what that'd do is try and ask the >> Injector to make an instance of Cheese - kinda like Spring's >> BeanContext.getBeanForType(Class) and the similar operation in Pico. >> Thoughts? >> > > +1 overall. In fact I mentioned this to you last year James> > This would change the rules about 'new' always meaning... > 1) space allocation for the new instance to hold the fields. > 2) initialisation of fields to default values. > 3) calling the appropriate constructor. > > And instead...? > - skipping all three stages and obtaining from pico et all? > - skipping some of the stages? > > How loose would the 'new' contract become? > - would you always get the same reference back (singleton) > - does 'new' have to be threadsafe? > - would this muck up garbage collection algorithms? > > should we use a different keyword e.g. make, so that the heap > allocation > vs dependancy injection usage is obvious... > e.g. > def f = make Cheese() > > See chapter 12 section 5 of > http://java.sun.com/docs/books/jls/download/langspec-3.0.pdf for > discussion of Java on the topic of 'new' execution... > > cheers, > jez. > -- > http://javanicus.com/blog2 > James ------- http://radio.weblogs.com/0112098/
>
> This would change the rules about 'new' always meaning...
> 1) space allocation for the new instance to hold the fields.
> 2) initialisation of fields to default values.
> 3) calling the appropriate constructor.
>
> And instead...?
> - skipping all three stages and obtaining from pico et all?
> - skipping some of the stages?
>
> How loose would the 'new' contract become?
> - would you always get the same reference back (singleton)
> - does 'new' have to be threadsafe?
> - would this muck up garbage collection algorithms?
>
> should we use a different keyword e.g. make, so that the heap
> allocation
> vs dependancy injection usage is obvious...
> e.g.
> def f = make Cheese()
>
> See chapter 12 section 5 of
>
RSS Feed