Abstract Factory
class User {
constructor(name, role, pages) {
this.name = name
this.role = role
this.pages = pages
}
greeting() {
console.log('hello,' + this.name);
}
dataShow() {
console.log('data');
}
}
class SuperAdmin extends User {
constructor(name) {
super(name, 'SuperAdmin', ['home', 'news', 'user', 'right'])
}
dataShow() {
console.log('your datashow');
}
addUser() {
console.log('you can add user');
}
addRight() {
console.log('you can add right');
}
}
class Admin extends User {
constructor(name) {
super(name, 'Admin', ['home', 'news', 'user'])
}
dataShow() {
console.log('your datashow');
}
addUser() {
console.log('you can add user');
}
}
class Editor extends User {
constructor(name) {
super(name, 'Editor', ['home', 'news'])
}
dataShow() {
console.log('your datashow');
}
}
function AbstractFactory(role) {
switch (role) {
case 'SuperAdmin':
return SuperAdmin;
break;
case 'Admin':
return Admin;
break;
case 'Editor':
return Editor;
break;
default:
return new Error('Wrong Para')
break;
}
}