public class Client {
private MyInterface var;
...
public Client(MyInterface var1) {
var = var1;
// Instead of var = new MyImplementation();
}
...
}
Now without any reference to the actual implementation, we can write the client program. The method described above is also known as Constructor Injection (which is a variant of Dependency Injection). The other variant is Setter Injection, in which a setter is provided to set the value of the dependency (MyImplementation in the above example). Martin fowler has nice introduction to depency injection on his website.
No comments:
Post a Comment