- 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");
推薦閱讀
- 少兒人工智能趣味入門:Scratch 3.0動畫與游戲編程
- 高手是如何做產品設計的(全2冊)
- PyTorch自動駕駛視覺感知算法實戰
- C++ Builder 6.0下OpenGL編程技術
- Web Development with Django Cookbook
- 數據結構(Java語言描述)
- Python數據可視化之Matplotlib與Pyecharts實戰
- PHP編程基礎與實例教程
- Visual Foxpro 9.0數據庫程序設計教程
- Python圖形化編程(微課版)
- Regression Analysis with Python
- Java Web從入門到精通(第3版)
- SciPy Recipes
- Learning Ionic
- Python趣味編程與精彩實例