Last active
August 29, 2015 13:56
-
-
Save raultm/9060821 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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