View difference between Paste ID: EifXyMMy and f9xdLYxH
SHOW: | | - or go back to the newest paste.
1
interface Salary {
2-
	private int salary;
2+
  public double getValue() { ... }
3
}
4-
	public int getSalary(){
4+
5-
		if salary == 0 //lazy load
5+
	private Salary salary;
6-
			calculateSalary();
6+
7-
		
7+
	public Salary getSalary(){
8
		if(!salary.isLoaded())
9
			salary = new LazySalary(this);
10
		return salary
11-
	public void calculateSalary(){
11+
12-
		...
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
}