Thursday, April 26, 2012

Dependency Injection

Dependency Injection is a way to make an object work with different implementations of an interface it is dependent on without recompilation of itself.

interface B{
work();
}

class Bimpl() implements B{
(){
  walking;
}
}

class A {
 public B b = new Bimpl();

doWork(){
 b.work();
}

}

For object of Class A to walk it needs Bimpl object.Say for example we need another another implementation of B to replace current Bimpl and that will require a code modification and recompilation of A.

3 types,
Constructor
Setter
Interface



No comments:

Post a Comment