Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- interface Salary {
- public double getValue() { ... }
- }
- class Employee{
- private Salary salary;
- public Salary getSalary(){
- if(!salary.isLoaded())
- salary = new LazySalary(this);
- return salary
- }
- private class LazySalary implements Salary {
- public double getValue() {
- Employee.this.calculateSalary();
- return Employee.this.getSalary().getValue();
- }
- }
- public class ConcreteSalary implements Salary {
- ...
- }
- private void calculateSalary(){
- ... // calcula mesmo o valor
- salary = new ConcreteSalary(value);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement