- 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.
推薦閱讀
- Clojure for Domain:specific Languages
- Kali Linux Wireless Penetration Testing Beginner's Guide(Third Edition)
- Python數(shù)據(jù)挖掘與機(jī)器學(xué)習(xí)實(shí)戰(zhàn)
- Building RESTful Python Web Services
- 軟件測(cè)試實(shí)用教程
- Python程序設(shè)計(jì)與算法基礎(chǔ)教程(第2版)(微課版)
- Python Social Media Analytics
- 征服C指針(第2版)
- Zend Framework 2 Cookbook
- 深度學(xué)習(xí)的數(shù)學(xué):使用Python語言
- 數(shù)據(jù)庫基礎(chǔ)與應(yīng)用實(shí)驗(yàn)教程:Visual FoxPro 6.0
- Mastering Python for Data Science
- C++ Primer(中文版)(第5版)
- R語言
- 架構(gòu)寶典