|
汽车实现类
public class BmwX3Car extends Car {
private PartsFactory factory;
public BmwX3Car(PartsFactory factory) {
this.factory = factory;
name = "BMW X3";
// 一个发动机
engines = new Engine[] { this.factory.createEngine() };
// 四个车轮
wheels = new Wheel[] { this.factory.createWheel(), this.factory.createWheel(), this.factory.createWheel(),
this.factory.createWheel() };
// 两个车灯
lamps = new Lamp[] { this.factory.createLamp(), this.factory.createLamp() };
}
}
public class BmwX5Car extends Car {
private PartsFactory factory;
public BmwX5Car(PartsFactory factory) {
this.factory = factory;
name = "BMW X5";
// 两个发动机
engines = new Engine[] { this.factory.createEngine(), this.factory.createEngine() };
// 四个车轮
wheels = new Wheel[] { this.factory.createWheel(), this.factory.createWheel(), this.factory.createWheel(),
this.factory.createWheel() };
// 四个车灯
lamps = new Lamp[] { this.factory.createLamp(), this.factory.createLamp(), this.factory.createLamp(),
this.factory.createLamp() };
}
}
public class BmwX7Car extends Car {
private PartsFactory factory;
public BmwX7Car(PartsFactory factory) {
this.factory = factory;
name = "BMW X7";
// 四个发动机
engines = new Engine[] { this.factory.createEngine(), this.factory.createEngine(), this.factory.createEngine(),
this.factory.createEngine() };
// 四个车轮和一个备用胎
wheels = new Wheel[] { this.factory.createWheel(), this.factory.createWheel(), this.factory.createWheel(),
this.factory.createWheel(), this.factory.createWheel() };
// 六个车灯
lamps = new Lamp[] { this.factory.createLamp(), this.factory.createLamp(), this.factory.createLamp(),
this.factory.createLamp() };
}
} |
|