Showing posts with label Dependency Injection. Show all posts
Showing posts with label Dependency Injection. Show all posts

Monday, 21 September 2015

The Dependency Inversion Principle And The Dependency Injection Pattern

Following on from a previous blog about Inversion of Control, I intend to continue by discussing the patterns identified in that article as being IoC patterns, or rather implementation patterns which enable the application of the IoC concept. Specifically in this post we will be looking at the Dependency Injection pattern, which will be followed up by a post on the Service Locator anti-pattern.

What is the Dependency Inversion Principle?

The dependency inversion principle refers to a specific form of decoupling software modules. When following this principle, the conventional dependency relationships established from high-level, policy-setting modules to low-level, dependency modules are inverted (i.e. reversed), thus rendering high-level modules independent of the low-level module implementation details.

Thursday, 27 August 2009

Inversion of Control (IoC)


What exactly does that mean?

At the heart of the matter IoC is all about loosely coupled software components.

Class1 has a member of type Class2 which is specified at design time.


Class1 has a member of type Interface1, and Class2 is an implementation of Interface1.


What is the difference between these two approaches as presented above?

The second example clearly involves more code? One might think then that in fact the first approach is better, or even that it is "cleaner"; it is quicker to write, it is simple to understand, and it results in fewer source files.