Advertisement
duc-phan

Untitled

Nov 30th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.78 KB | None | 0 0
  1. public abstract class Employee {
  2.     public abstract boolean isPayday();
  3.     public abstract Money calculatePay();
  4.     public abstract void deliverPay(Money pay);
  5. }
  6.  
  7. public interface EmployeeFactory {
  8.     public Employee makeEmployee(EmployeeRecord r) throws InvalidEmployeeType;
  9. }
  10.  
  11. public class EmployeeFactoryImpl implements EmployeeFactory {
  12.     public Employee makeEmployee(EmployeeRecord r) throws InvalidEmployeeType {
  13.         switch (r.type) {
  14.             case COMMISSIONED:
  15.                 return new CommissionedEmployee(r) ;
  16.             case HOURLY:
  17.                 return new HourlyEmployee(r);
  18.             case SALARIED:
  19.                 return new SalariedEmploye(r);
  20.             default:
  21.                 throw new InvalidEmployeeType(r.type);
  22.         }
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement