Announcement Announcement Module
Collapse
No announcement yet.
DI vs IOC and Patterns Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • DI vs IOC and Patterns

    I need help resolving 2 issues.

    After sending this link

    http://www.theserverside.com/news/th...hread_id=23358

    to a colleague and after pointing out the posts by Martin Fowler himself, this colleague maintains an original position that IoC Dependency Injection are 2 different things. Are they 2 separate things ?

    Secondly, when posed with the question what pattern is most at play when you think DI he says Factory. I say Strategy or Template.

    Rod Johnson introduces the IoC concept in the context of discussing the Template Method and Strategy patterns. See here (goto page 7):
    http://media.techtarget.com/tss/stat...onChapter4.pdf

    The real question here is, which pattern mostly resembles DI in action, Factory or Strategy/Template Method (given these 2 choices) ? To elaborate, when Rod Johnson was conceiving the ideas regarding IoC in his original book, was he trying to solve a problem that could be solved with a Factory pattern or was the Factory pattern insufficient for the problem ?

  • #2
    IoC > DI

    1) Martin Fowler's definition of Inversion of Control includes both Dependency Injection and Service Location. In other words, Dependency Injection is a specific type of IoC.

    2) DI != Factory. DI != Strategy. DI relates to both, but mostly resembles the Builder Pattern

    Comment


    • #3
      DI != Builder

      Thanks for the reply.
      Fowler clearly writes that IoC was renamed to DI. He does not say that DI is a type of IoC. I know this is how it's perceived now(and perhaps rightfully so), but that's not what Fowler wrote. He did write this:

      When these containers talk about how they are so useful because they implement "Inversion of Control" I end up very puzzled. Inversion of control is a common characteristic of frameworks, so saying that these lightweight containers are special because they use inversion of control is like saying my car is special because it has wheels.

      ...

      As a result I think we need a more specific name for this pattern. Inversion of Control is too generic a term, and thus people find it confusing. As a result with a lot of discussion with various IoC advocates we settled on the name Dependency Injection.
      Those are Fowler's words from the linked article. I'm interested in what Fowler and Johnson intended more so than how it's currently percieved.

      I can buy the Builder Pattern argument (perhaps based purely on definition) but I can also buy the Factory Pattern argument. This part of the debate was in the context of Spring's intentions. That's why I referenced Rod Johnson's book. He mentions IoC in the context of the Template Method Pattern and I believe at the time he was writing this he was probably using this pattern to solve a problem in an IoC type of way. I think it's also relevant that he goes on to reference the Strategy Pattern. But I guess only he can really answer this.

      Comment


      • #4
        Originally posted by dsmith View Post
        Thanks for the reply.
        Fowler clearly writes that IoC was renamed to DI. He does not say that DI is a type of IoC. I know this is how it's perceived now(and perhaps rightfully so), but that's not what Fowler wrote. He did write this:

        As a result I think we need a more specific name for this pattern. Inversion of Control is too generic a term, and thus people find it confusing. As a result with a lot of discussion with various IoC advocates we settled on the name Dependency Injection.
        Those are Fowler's words from the linked article. I'm interested in what Fowler and Johnson intended more so than how it's currently percieved.
        <snip>
        He also says:

        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.
        Doesn't that imply that "Dependency Injection" is a more specific type of "Inversion of Control?" In the end, it's all just terminology.

        (Martin Fowler is a self proclaimed compulsive Neologist. He speaks about IoC vs. DI. The term DI was his invention, and he talks a bit about why he created it)

        Comment


        • #5
          Originally posted by Solomon View Post
          He also says:



          Doesn't that imply that "Dependency Injection" is a more specific type of "Inversion of Control?" In the end, it's all just terminology.

          (Martin Fowler is a self proclaimed compulsive Neologist. He speaks about IoC vs. DI. The term DI was his invention, and he talks a bit about why he created it)
          No, it doesn't. It's pretty clear now, DI = IoC.

          Comment

          Working...
          X