Created
August 12, 2015 03:39
-
-
Save jpetitto/51206d5931dbdd3af785 to your computer and use it in GitHub Desktop.
Dependency Injection Example
This file contains 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 Refrigerator { | |
private PowerSource powerSource; | |
public Refrigerator() { | |
powerSource = new AcPowerSource(); | |
} | |
} | |
// with DI (manual) | |
public class Refrigerator { | |
private PowerSource powerSource; | |
public Refrigerator(PowerSource powerSource) { | |
this.powerSource = powerSource; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment