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

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.

主站蜘蛛池模板: 永济市| 延吉市| 寿阳县| 郧西县| 同仁县| 邢台市| 马公市| 绥宁县| 娄底市| 南汇区| 滦平县| 贵南县| 洛阳市| 西吉县| 周口市| 股票| 贵州省| 砚山县| 盖州市| 祁阳县| 辽源市| 林芝县| 象山县| 万源市| 江城| 分宜县| 恩平市| 剑河县| 伊春市| 武穴市| 湖口县| 商南县| 九龙县| 高陵县| 镶黄旗| 全南县| 霞浦县| 丰城市| 浠水县| 庄河市| 湘西|