Re: If I'm an object - how can I pass myself instantly after my construction.
Posted By:
joe_heath
Posted On:
Tuesday, July 3, 2001 07:42 AM
The pattern you need is a Factory.
If the object can only be created using the factory you can create the object and then perform operations with it before returning it..
eg.
public class User {
//note only this package can create these
User() {
}
}
public class UserFactory {
public User getUser() {
User user = new User();
if (login(user))
return user;
else
return null;
}
}
Use:
User loggedUser = myUserFactory.getUser();
You might also want to make the UserFactory a singleton and hold a state..