2 ms·
An arguably better solution, at least in statically typed languages, is to make the type keys constant objects that implement a `setup(user)` method, which for
by layer8 5y ago
An arguably better solution, at least in statically typed languages, is to make the type keys constant objects that implement a `setup(user)` method, which for example is possible in Java by using an enum type for the keys. E.g.:
enum UserType {
ADMIN { void setup(User) { … } },
CUSTOMER { void setup(User) { … } },
;
abstract void setup(User);
}
and then have:
User createUser(UserType type, UserAttributes attributes) {
User user = new User(attributes);
type.setup(user);
user.setupNotifications();
return user;
}