I just watched an Inversion of Control course on Pluralsight. I get it now, but I’m writ­ing this down to make sure I get it to­mor­row.

  • Dependency Inversion Principle - ac­cessed items should not de­pend on ac­ces­sor items
  • Inversion of Control
    • a pat­tern to solve” the Dependency Inversion Principle
    • ac­ces­sor tells ac­cessed how they will in­ter­act
    • Interface in­ver­sion - ac­ces­sor cre­ates in­ter­face rather than ac­cessed
    • Flow in­ver­sion - event-dri­ven in­stead of pro­ce­dural pro­gram­ming
    • Creation in­ver­sion - ob­ject is cre­ated out­side of the class it is used in -
      • fac­tory pat­tern (Button button = ButtonFactory.CreateButton();)
      • ser­vice lo­ca­tor (Button button = ServiceLocator.Create(IButton.class);)
      • de­pen­dency in­jec­tion
  • Dependency Injection
    • de­pen­dency is cre­ated out­side of class that de­pends on it
    • dif­fers from cre­ation in­ver­sion be­cause it spec­i­fies that the de­pen­dency is not cre­ated by the de­pen­dent; in e.g. the fac­tory pat­tern, the de­pen­dent is still re­spon­si­ble for cre­at­ing the de­pen­dent by call­ing the fac­tory
    • Constructor Injection
      • most com­mon
      • de­pen­dency is passed into con­struc­tor and stored as field in ob­ject
    • Setter Injection
      • de­pen­dency is passed into set­ter and stored as field in ob­ject
    • Interface Injection
      • class has in­ter­face which re­quires a set­ter
      • when call­ing cast the class as the in­ter­face and call the in­ter­face’s set­ter
      • more ex­plicit than just a set­ter
  • IoC Container
    • frame­work for do­ing de­pen­dency in­jec­tion
    • re­solves the chain of de­pen­den­cies

They aren’t dif­fi­cult con­cepts. Really, the most dif­fi­cult part is keep­ing all the ter­mi­nol­ogy straight.