Skip to content

Instantly share code, notes, and snippets.

@jpetitto
Created August 12, 2015 03:39
Show Gist options
  • Save jpetitto/51206d5931dbdd3af785 to your computer and use it in GitHub Desktop.
Save jpetitto/51206d5931dbdd3af785 to your computer and use it in GitHub Desktop.
Dependency Injection Example
// 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