(According to the msdn webcast courses)
New Problem: Implementing dependencies cannot cope with changes in the specific instantiation type. (When the instance object changes, it cannot meet the requirements)
Example:
When a road is prone to change and may become a mudroad, You need to modify all the new to road locations in the system.
Solution:
Closed change point-where to change and where to close; if the new type is relatively stable, there is basically no need to encapsulate it.
The created object is easy to change, so it is necessary to encapsulate the process of object creation.
Interface-Oriented Programming: Dependent interfaces instead of dependency implementation
Abstract The road classes, create a series of different types of child classes, and instantiate them in the createxx aspect as needed. Benefits: customers are not affected when changes are required.Program, You only need to modify the class library.
Create a series of mutually dependent objects
Problems with this simple factory:
It cannot cope with changes to "objects dependent on different series. For example, the border skin of different styles is usually a set of dependent objects. When the style changes, these objects should change accordingly.
Solution:
Or encapsulation changes. A plug-in mechanism is provided to avoid tight coupling between the customer program and the creation of specific objects in multiple systems.
Gof: provides an interface for this interface to create a series of "related or interdependent objects" without specifying their specific classes.
Producta and B are specific to the series 1 and 2, respectively, and the two products in the series are mutually dependent. They are instantiated through concreterfactory1 and 2. The customer program only needs to operate the three interfaces provided by the class library to instantiate different series of products.
Abstract Factory mode:
The change is the combination of different styles and series, rather than the increase or decrease of specific product objects or various parts within the product.
Conclusion