Open Pcjmy opened 1 year ago
// 工厂类 class shapeFactory { chooseShape (type) { if (type === 'circle') { return new Circle() } if (type === 'rectangle'){ // ... } } } // 圆形类 class Circle { draw () { console.log('the shape is circle') } } const factory = new shapeFactory() factory.chooseShape('circle')