cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Joerg Heinicke <joerg.heini...@gmx.de>
Subject Re: [RT] Simplifying component handling
Date Sat, 31 Dec 2005 13:56:22 GMT
On 30.12.2005 19:09, Carsten Ziegeler wrote:

> class MyComponent implements SOMETHING, ThreadSafe, Disposable,
> Serviceable {
> protected ClassA compA;
> protected ClassB compB;
> protected ServiceManager m;
> 
> public void service(ServiceManager m) {
>   this.m = m;
>   compA = (ClassA)m.lookup(ClassA.ROLE);
>   compB = (ClassB)m.lookup(ClassB.ROLE);
> }
> public void dispose() {
>   if ( m != null ) {
>     m.release(compA);
>     m.release(compB);
>   }
> }
> 
> Way too much code me thinks. So what about:
> 
> class MyComponent implements SOMETHING, ThreadSafe {
>   protected final ClassA compA;
>   protected final ClassB compB;
> 
>   public MyComponent(ClassA a, ClassB b) {
>     compA = a;
>     compB = b;
>   }
> }
> 
> We could simply add constructor injection: if the implementation does
> not provide a default constructor, the available constructor is called
> using reflection and the components are injected on construction of the
> object - no need to configure something in any xml configuration file.
> Implementing this is easy - I did this already years ago for Fortress.

What's the contract for the auto-wiring? Just assuming ClassA and ClassB 
have public static fields called ROLE? Sounds somewhat "strange".

Jörg

Mime
View raw message