console.log("工厂模式")
class Tank{
exe(){
console.log("运行:"+this.specification);
}
}
class B50Tank extends Tank{
constructor(){
super();
this.specification = "50坦克";
}
}
class B70Tank extends Tank{
constructor(){
super();
this.specification = "70坦克";
}
}
class Creater{
AnOperation(){
var tank = this.FactoryMethod();
tank.exe();
}
}
class B50ConcretCreater extends Creater{
FactoryMethod(){
return new B50Tank();
}
}
class B70ConcretCreater extends Creater{
FactoryMethod(){
return new B70Tank();
}
}
var crete = new B50ConcretCreater();
crete.AnOperation();
var crete = new B70ConcretCreater();
crete.AnOperation();