[ProgClub list] What is IoC?
jj5 at progclub.org
Tue Oct 11 15:50:01 AEDT 2011
On 11/10/2011 3:57 AM, Stuart Laughlin wrote:
> 1: My favorite at the moment is by Martin Fowler at
Thanks for your explanation and links Stuart. I haven't read all your
emails yet, but I will. I just wanted to throw in an off-the-cuff remark
about this quote from Fowler:
"In this article I dig into how this pattern works, under the more
specific name of "Dependency Injection", and contrast it with the
Service Locator alternative. The choice between them is less important
than the principle of separating configuration from use."
So it seems like the object of IoC is to separate configuration from
use, and my knee-jerk reaction to that would be to use a factory. So
from your example you would configure Notifier to use a factory to
create its IMessageClient (which concretely might be a EmailSender) and
if you want to configure Notifier some other way (for testing or
improvement) then you could just create a different factory that created
the new IMessageClient. In your testing code you'd configure a mock
message client that just logged to the console or something like that,
and in your production system you'd use a real IMessageClient
implementation handed out by the factory.
So far I don't see what IoC buys me, but I'll keep reading.
More information about the list