官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 临西县| 泾川县| 门源| 望江县| 五华县| 永兴县| 马鞍山市| 泗洪县| 高青县| 东乌珠穆沁旗| 祁门县| 奉贤区| 临洮县| 焦作市| 静海县| 大竹县| 桐乡市| 灵武市| 晋中市| 太康县| 永胜县| 阿鲁科尔沁旗| 旬邑县| 东辽县| 云霄县| 吉林省| 利川市| 乌兰县| 武义县| 阳谷县| 台北县| 若羌县| 巴楚县| 宁海县| 东丰县| 成安县| 固安县| 桃园县| 若尔盖县| 昂仁县| 静海县|