Search
抽象工厂模式(Abstract Factory Pattern)是围绕一个超级工厂创建其他工厂。该超级工厂又称为其他工厂的工厂。这种类型的设计模式属于创建型模式,它提供了一种创建对象的最佳方式。
class Employee { constructor(name) { this.name = name; } say() { console.log(`I am ${this.name}`); } } class EmployeeFactory { constructor() {} create(name) { return new Employee(name); } } export { EmployeeFactory };
const employeeFactory = new EmployeeFactory(); const dao = employeeFactory.create("DaoLang"); dao.say();