- 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.
推薦閱讀
- 解構(gòu)產(chǎn)品經(jīng)理:互聯(lián)網(wǎng)產(chǎn)品策劃入門寶典
- 信息可視化的藝術(shù):信息可視化在英國
- CentOS 7 Linux Server Cookbook(Second Edition)
- 征服RIA
- Windows Forensics Cookbook
- Cocos2d-x學(xué)習(xí)筆記:完全掌握Lua API與游戲項(xiàng)目開發(fā) (未來書庫)
- Python機(jī)器學(xué)習(xí)基礎(chǔ)教程
- Android移動(dòng)開發(fā)案例教程:基于Android Studio開發(fā)環(huán)境
- Natural Language Processing with Python Quick Start Guide
- Exploring SE for Android
- UI動(dòng)效設(shè)計(jì)從入門到精通
- JBoss AS 7 Development
- HTML 5與CSS 3權(quán)威指南(第4版·下冊(cè))
- Scratch少兒編程思維訓(xùn)練:培養(yǎng)孩子的邏輯思維和計(jì)算思維能力
- Learning Puppet Security