Writing Clean & Maintainable Code
What is the benefit of implementing the Factory Pattern in JavaScript?
class UserFactory {
static createUser(type) {
switch(type) {
case 'admin':
return new AdminUser();
case 'customer':
return new CustomerUser();
default:
throw new Error('Invalid user type');
}
}
}