avalon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "MCCAY,LARRY (HP-NewJersey,ex2)" <lawrence_mccay-...@hp.com>
Subject RE: Inversion of Control Question
Date Fri, 18 Jan 2002 23:25:46 GMT
Ryan,

I don't believe that spirit of IOC is violated in any way by passing
references to the parent.

The example you provide in the DefaultThreadPool is actually a good example
of interface based programming.  The this pointer is provided to the child
component as an implementation of ObjectFactory - the
SoftResourceLimitingPool is unaware of it being any other implementation.
In the spirit of IOC, the SoftResourceLimitingPool needs an ObjectFactory to
get its job done and it must be provided to it by the creator - in tis case
DefaultThreadPool.
>         m_pool = new SoftResourceLimitingPool( this, capacity );

Hope this helps.

Thanks,

--Larry

> -----Original Message-----
> From: Ryan Shaw [mailto:ryan@silveregg.co.jp]
> Sent: Thursday, January 17, 2002 9:40 PM
> To: avalon-dev@jakarta.apache.org
> Subject: Inversion of Control Question
> 
> 
> Hello,
> 
> My coworkers and I are just starteing to get heavily
> involved in using Avalon. We understand the existing
> packages pretty well, but there are still some conceptual
> issues we are struggling with.
> 
> One idea we are having trouble with is Inversion of
> Control. We understand it abstractly, but when it comes
> down to specific situations we sometimes are having
> trouble deciding whether or not something breaks IOC.
> 
> For example, suppose that the ThreadPool implementation
> in Excalibur scratchpad extended SoftResourceLimitingPool
> (it doesn't, but for the sake of argument suppose it did).
> Then when it created new WorkerThreads it would pass 
> itself as a reference so that threads could put themselves
> back in the pool when they finished tasks.
> 
> Does this break IOC, because a container (the pool) is
> passing a reference to itself to the things it is 
> managing?
> 
> For that matter, the ThreadPool implementation in the
> scratchpad creates a SoftResourceLimitingPool and passes
> a reference to itself as the ObjectFactory to use:
> 
>     public DefaultThreadPool( final String name,
>                               final int capacity,
>                               final ThreadContext context )
>         throws Exception
>     {
>         super( name );
>         m_pool = new SoftResourceLimitingPool( this, capacity );
>         m_context = context;
>     }
> 
> Doesn't this also break IOC (child component now has reference
> to parent)?
> 
> If these examples don't break IOC, please explain why. If they 
> do, please explain when it is okay to break IOC and when it 
> isn't.
> 
> Thanks for any light you can shed on this.
> 
> Ryan
> 
> --
> To unsubscribe, e-mail:   
<mailto:avalon-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:avalon-dev-help@jakarta.apache.org>

--
To unsubscribe, e-mail:   <mailto:avalon-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:avalon-dev-help@jakarta.apache.org>


Mime
View raw message