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

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.

主站蜘蛛池模板: 青神县| 赤水市| 阜平县| 五寨县| 唐山市| 兴宁市| 广水市| 琼中| 光山县| 定日县| 略阳县| 清苑县| 巴彦淖尔市| 仪陇县| 白河县| 岑溪市| 革吉县| 富平县| 西宁市| 崇礼县| 吉林省| 胶州市| 凌海市| 台安县| 偏关县| 林芝县| 三穗县| 郁南县| 五莲县| 赤壁市| 蓬莱市| 新巴尔虎右旗| 当阳市| 集安市| 昭苏县| 寿光市| 若羌县| 上杭县| 含山县| 英吉沙县| 喜德县|