Skip to content

Instantly share code, notes, and snippets.

@raultm
Last active August 29, 2015 13:56
Show Gist options
  • Save raultm/9060821 to your computer and use it in GitHub Desktop.
Save raultm/9060821 to your computer and use it in GitHub Desktop.
// No DI
public class Car{
private Motor motor;
public Car(){
motor = new ElectricMotor();
}
}
// DI in Constructor
public class Car{
private Motor motor;
public Car(Motor motor){
this.motor = motor;
}
}
// DI in Setter
public class Car{
private Motor motor;
public Car(){
}
public void setMotor(Motor motor){
this.motor = motor;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment