RSS

Dependency Inversion X Inversion Control X Dependency Injection

04 Jul

Dependency Inversion Principle
Definition: Instead of lowel level modules defining an interface that higher level modules depend on, higher level modules define an interface that lower level modules implement.
Example: portable chargeable devices, the copy program (read and write)

Inversion of Control

  • Interface inversion
    The user of the class defines the interface
    Interface should have more than 1 implementation
  • Flow inversion
    Procedural VS Event driven
  • Creation / binding inversion
    Creating objects outside of the class they are being used in.

Dependency Injection
A type of IOC where we move the creation and binding of a dependency outside of the class that depends on it.
Example: packing a lunch VS lunch is provided.

  • Constructor Injection
    Pass dependency into dependent class via constructor.
  • Setter Injection
    Create a setter on the dependent class and use the setter to set the dependency.
  • Interface Injection
    Dependent class implements an interface. Injector uses the interface to set the dependency.
Advertisements
 
Leave a comment

Posted by on July 4, 2012 in References

 

Tags: ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

 
%d bloggers like this: