There is a flaw in the simple factory model that violates the open and closed principle. The factory method mode avoids just one point.
Opening and closing principle definition: A software entity should open for extension and close for modification. and software entities shall
Try to extend it without modifying the original code.
Opening and closing principle: http://blog.csdn.net/lovelion/article/details/7537584
Factory method Mode Overview:
The Factory parent is responsible for defining the public interface that creates the product object, while the factory subclass is responsible for generating the specific product object.
The factory method pattern consists of the following 4 roles: ?Product(abstract products)?concreteproduct(Specific products)?Factory(abstract Factory)?concretefactory(Specific factory)
Advantages:1, the factory method is used to create the customer needs of the product, but also to the customer hidden what kind of specific product class will be instantiated this detail2.can belet the factory determine what product object to create, and the details of how to create this object are completely encapsulated inside the specific factory fully comply with the open and closed principle when adding new products to the system
Disadvantages:1, the number of classes in the system will increase, to a certain extent, increase the complexity of the system, will bring some additional overheadincreases the abstraction and difficulty of comprehension of the system
C # Factory Method mode