Skip to content

Instantly share code, notes, and snippets.

@efleming969
Last active August 29, 2015 14:19
Show Gist options
  • Select an option

  • Save efleming969/36fb2607e418918faa26 to your computer and use it in GitHub Desktop.

Select an option

Save efleming969/36fb2607e418918faa26 to your computer and use it in GitHub Desktop.
SOLID: Dependency Inversion
class PayCalculator {
public static long totalPayForEmployee ( HourlyEmployee employee ) {
RateRepository rr = new RateRepository ();
long rate = rr.getRateById ( employee.id );
return rate * employee.hours;
}
}
class RateRepository {
public long getRateById ( String id ) {
if ( id == "1" )
return 200;
else
return 20;
}
}
class HourlyEmployee {
public long hours = 0;
public String id = "";
public HourlyEmployee ( String id, long hours ) {
this.id = id;
this.hours = hours;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment