factory question
I have this interface:
publicinterface
UserInfo{
public StringgetUid();
public StringgetKps();
public StringgetName();
public List<String> getRoles();
public StringgetMainRole();
public StringgetClientHost();
publicfloatgetBalance();
public List<ChargeKey>getCharges();
public List<PrintHistory>getHistory();
}
I have a UserFactory class that has 2 methods, getParameterUser() and getLoginUser(), both return UserInfo by doing UserImpl user =new UserImpl(uid, utils);
Where UserImpl implements UserInfo, and they return that. The utils parameter is a utility class that has several utility methods that do things like ldap lookups and other stuff to fill in the first 5 fields (excluding uid which is passed in), uid, kps, name, roles, mainRole, clientHost. The balance, charges, and history fields are filled in by calls to data access object methods. There are separate DAOs for each one (balance, charges, and history).
I would like to keep instances of the UserInfo fairly lightweight and it's immutable so it has only getters, no setters.
I couldn't see a way to set the balance, charges, and history fields from within the UserImpl other than passing in the DAOs, or by having setters for them and injecting them, but then it's either ugly with a lot of parameters to its constructor or it has references to the DAOs that it only uses once to set itself up.
The UserFactory, UserInfo, and UserImpl are the only classes in the package xyz.user so remembering that in Effective Java he said it's ok to have fields that are package private I made balance, charges, and history package private and they're set in the UserFactory getLoginUser and getParameterUser methods.final UserImpl user =new UserImpl(uid, utils);
/*
* Set the package-private fields.
*/
user.charges = chargeHistoryDao.get(uid);
user.balance = balanceDao.getBalance(user.getKps());
user.history = printHistoryDao.getHistory(user.getKps());
return(user);
But now I'm wondering why bother doing any setup in the UserImpl's constructor. Why not just make all of its fields package private and set them all up in the factory? So that all UserImpl has is fields and getter methods and no code in its constructor.
Does this make sense? Good or bad idea?

