//父类 车辆
class Car{
constructor(number, name){
this.name = name;
this.number = number;
}
}
//快车
class Kuaiche extends Car{
constructor(number, name, pice){
super(number, name);
this.pice = 1;
}
}
//专车
class Zhuanche extends Car{
constructor(number, name, pice){
super(number, name);
this.pice = 5;
}
}
//行程
class Tirp{
constructor(car){
this.car = car;
}
start(){
console.log(`行程开始 名称${this.car.name} ,车牌号${this.car.number}`);
}
end(){
console.log('行程结束'+ this.car.pice*5);
}
}
let car = new Kuaiche('D7745', '奔驰');
let tirp = new Tirp(car);
tirp.start();
tirp.end();
设计原则实例1
最新推荐文章于 2024-07-22 14:17:37 发布