- Design Patterns and Best Practices in Java
- Kamalmeet Singh Adrian Ianculescu LUCIAN PAUL TORJE
- 80字
- 2021-06-25 20:52:33
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");
推薦閱讀
- C#高級(jí)編程(第10版) C# 6 & .NET Core 1.0 (.NET開(kāi)發(fā)經(jīng)典名著)
- Google Apps Script for Beginners
- 兩周自制腳本語(yǔ)言
- Apache Spark Graph Processing
- UI智能化與前端智能化:工程技術(shù)、實(shí)現(xiàn)方法與編程思想
- Nginx Essentials
- Mastering KnockoutJS
- Apache Camel Developer's Cookbook
- Orchestrating Docker
- C++從入門(mén)到精通(第6版)
- Photoshop CC移動(dòng)UI設(shè)計(jì)案例教程(全彩慕課版·第2版)
- 深入淺出 HTTPS:從原理到實(shí)戰(zhàn)
- 現(xiàn)代C++語(yǔ)言核心特性解析
- Apache Kafka 1.0 Cookbook
- Python程序設(shè)計(jì)現(xiàn)代方法