Last active
August 29, 2015 14:19
-
-
Save efleming969/36fb2607e418918faa26 to your computer and use it in GitHub Desktop.
SOLID: Dependency Inversion
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
| 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