Pattern Design: Inversion of Control / Dependency Injection

The Design Patterns are tools that every developer nees to know to achieve better results in their software products.

One of the most important patterns we can use to decouple our classes are Inversion of Control and Dependency Injection. This principle is use in almost every framework we know, Spring for example, but is good to know it, even if we dont use any frameworks.

“Dependency Injection (DI) is a design pattern that strive to reduce the dependency between components. Dependency Injection is often referred as Inversion of Control (IoC). In fact dependency injection is an application of the Inversion of Control principle.”

A class that depends from an other object, receive the reference of the dependent object from the outside world instead of create the instance itself.


This is a good example of Inversion of Control, intead the control depends of the Lamp, this will depends of the Interface. with this pattern we invert the control of the model, no longer the control will depend of the lower modules, now it will depends of the interfaces.


Here we got a more complete example, now a Car will depends of objects that implement the IEngine Interface use, will not depends of objects from NormalEngine or TurboEngine Class, with this aproach we can get a decouple implementation.





Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de

Estás comentando usando tu cuenta de Cerrar sesión /  Cambiar )

Google+ photo

Estás comentando usando tu cuenta de Google+. Cerrar sesión /  Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión /  Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión /  Cambiar )


Conectando a %s

Subir ↑

A %d blogueros les gusta esto: