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:[EMAIL PROTECTED]]
> Sent: Thursday, January 17, 2002 9:40 PM
> To: [EMAIL PROTECTED]
> 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:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to