官术网_书友最值得收藏!

Anonymous concrete factory

We continue the previous code by adding a BikeFactory from where customers can select a small bike or a large bike. We can do this without creating a separate class file; we can simply create an anonymous class that extends the VehicleFactory directly in the client code:

VehicleFactory bikeFactory = new VehicleFactory() 
{
@Override
protected Vehicle createVehicle(String size)
{
if (size.equals("small"))
return new MountainBike();
else if (size.equals("large"))
return new CityBike();
return null;
}
};
bikeFactory.orderVehicle("large", "blue");
主站蜘蛛池模板: 高陵县| 剑河县| 万荣县| 徐水县| 获嘉县| 青河县| 西丰县| 行唐县| 响水县| 杨浦区| 龙井市| 灵武市| 泗洪县| 桐庐县| 鸡东县| 长白| 陇川县| 阳信县| 白山市| 香河县| 澎湖县| 宜宾市| 土默特右旗| 房产| 邵东县| 斗六市| 长武县| 微山县| 法库县| 郁南县| 清丰县| 鹿泉市| 祁门县| 康定县| 博乐市| 岢岚县| 舒兰市| 界首市| 蒲江县| 普洱| 报价|