- 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");
推薦閱讀
- Practical Data Analysis Cookbook
- Building a RESTful Web Service with Spring
- Mastering Natural Language Processing with Python
- PowerCLI Cookbook
- Selenium Design Patterns and Best Practices
- 基于差分進化的優化方法及應用
- Learning Laravel 4 Application Development
- QGIS:Becoming a GIS Power User
- MongoDB權威指南(第3版)
- Django 3.0入門與實踐
- Windows Phone 8 Game Development
- C++程序設計教程(第2版)
- jQuery從入門到精通(微課精編版)
- Visual Basic程序設計基礎
- AutoCAD基礎教程