tdudzik

SOLID - Single Responsibility Principle

Apr 11th, 2016
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.01 KB | None | 0 0
  1. /* Single Responsibility Principle */
  2.  
  3. // Before
  4. class Employee {
  5.  
  6.     private final String firstName;
  7.     private final String lastName;
  8.  
  9.     public Employee(String firstName, String lastName) {
  10.         this.firstName = firstName;
  11.         this.lastName = lastName;
  12.     }
  13.  
  14.     public String getFirstName() {
  15.         return firstName;
  16.     }
  17.  
  18.     public String getLastName() {
  19.         return lastName;
  20.     }
  21.  
  22.     public BigDecimal calculatePay() {
  23.         // Take taxes, bonuses, overtime etc. on board
  24.         return new BigDecimal("");
  25.     }
  26.  
  27. }
  28.  
  29. // After
  30. class Employee {
  31.  
  32.     private final String firstName;
  33.     private final String lastName;
  34.  
  35.     public Employee(String firstName, String lastName) {
  36.         this.firstName = firstName;
  37.         this.lastName = lastName;
  38.     }
  39.  
  40.     public String getFirstName() {
  41.         return firstName;
  42.     }
  43.  
  44.     public String getLastName() {
  45.         return lastName;
  46.     }
  47.  
  48. }
  49.  
  50. class PayCalculator {
  51.  
  52.     public BigDecimal calculatePay(Employee employee) {
  53.         // Calculate pay and take taxes, bonuses, overtime etc. on board
  54.         return new BigDecimal("");
  55.     }
  56.  
  57. }
Advertisement
Add Comment
Please, Sign In to add comment