Advertisement
michelchenrich

Untitled

Sep 29th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. interface Salary {
  2.   public double getValue() { ... }
  3. }
  4. class Employee{
  5.     private Salary salary;
  6.  
  7.     public Salary getSalary(){
  8.         if(!salary.isLoaded())
  9.             salary = new LazySalary(this);
  10.         return salary
  11.     }
  12.    
  13.     private class LazySalary implements Salary {
  14.       public double getValue() {
  15.          Employee.this.calculateSalary();
  16.          return Employee.this.getSalary().getValue();
  17.       }
  18.     }
  19.  
  20.     public class ConcreteSalary implements Salary {
  21.       ...
  22.     }
  23.  
  24.     private void calculateSalary(){
  25.         ... // calcula mesmo o valor
  26.         salary = new ConcreteSalary(value);
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement