How is that any different?

// Shared by all classes who need employee info
public class PayrollManager {
    public EmployeeInfo fetchEmployeeInfo() {
        // ...
        return new EmployeeInfo(...);
    }
}

// ----------
// Immutable
public class EmployeeInfo {
    public EmployeeInfo() {}
}
  • A new EmployeeInfo is returned for each lookup
  • PayrollManager does not store any state

11 / 22