- Design Patterns and Best Practices in Java
- Kamalmeet Singh Adrian Ianculescu LUCIAN PAUL TORJE
- 115字
- 2021-06-25 20:52:33
Simple factory pattern
The factory pattern is used to encapsulate the logic to instantiate objects referred through a common interface. New classes can be added with minimal changes.
The implementation of a simple factory is described in the following class diagram:

The SimpleFactory class implements the code to instantiate ConcreteProduct1 and ConcreteProduct2. When the client needs an object, it calls the createProduct() method of the SimpleFactory with the parameter indicating the type of object it requires. SimpleFactory instantiates the corresponding concrete product and returns it. The returned product is cast to the base class type so the client will handle any Product in the same way, regardless of whether it is a ConcreteProduct1 or ConcreteProduct2.
推薦閱讀
- Mastering JavaScript Functional Programming
- 數字媒體應用教程
- 大學計算機應用基礎實踐教程
- MATLAB圖像處理超級學習手冊
- 算法基礎:打開程序設計之門
- 軟件測試工程師面試秘籍
- 趣學Python算法100例
- Python Network Programming Cookbook(Second Edition)
- Python自然語言處理(微課版)
- 鋒利的SQL(第2版)
- 零基礎學Java程序設計
- Access 2016數據庫管
- Drupal 8 Configuration Management
- Java EE 7 Performance Tuning and Optimization
- C語言開發基礎教程(Dev-C++)(第2版)