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

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.

主站蜘蛛池模板: 文化| 新干县| 察哈| 广元市| 雅江县| 六安市| 商都县| 邢台县| 镇远县| 武义县| 高密市| 望谟县| 呼伦贝尔市| 光山县| 阿城市| 轮台县| 永修县| 剑川县| 聂拉木县| 集安市| 永年县| 武安市| 延寿县| 荥阳市| 山东| 自贡市| 灵川县| 连江县| 射洪县| 疏附县| 彭泽县| 子洲县| 宁化县| 新乡县| 都匀市| 沙坪坝区| 双柏县| 惠来县| 金平| 米易县| 微山县|