I've just read the Factory Pattern in the Head First Design Patterns Book. I'm just wondering if by default, the Spring uses this.
Let's say I have an AppConfigServiceImpl.java:
@Service("appConfigService")
public class AppConfigServiceImpl implements AppConfigService {
@Autowired
private UserService userService;
@Autowired
private IdGeneratorService idGeneratorService;
@Override
public void initializeUserId() {
final Integer lastUserId = userService.getLastId();
idGeneratorService.initialize(lastUserId);
}
}
Isn't the AppConfigService a Factory Class Interface? And the AppConfigServiceImpl is the concrete class. And the initializeUserId() the factory method?
Or what if I have a structure like this:
public abstract class User
public class AdminUser extends User
public class BusinessUser extends User
public class UserServiceImpl implements UserService {
@Override
public User getUser(String userType) {
if (UserType.ADMIN.toString.equalsIgnoreCase(userType)) {
return new AdminUser();
} else {
return new BusinessUser();
}
}
}
Aucun commentaire:
Enregistrer un commentaire