1. Create mode of design mode is divided into 5 categories: abstract factories, constructors, factory methods, prototypes, single example 2. Creation mode refers to getting object methods, how to build flexible through the structure between our classes , Extended strong object acquisition system. 3. These five categories can be described like this: 3.1 Abstract factory: It applies to a set of products, that is, we have a series of products, they consist of some style. A set of forms of forming systems. The system may have a lot of styles, so each style should correspond to a set of different products. We define an abstract factory, and the factory gives all the definitions of all abstract products, each The style is done by its specific factory definition. Therefore, how many specific factories are, it is how many groups are our product group. Each specific factory can do it to produce specific products. Of course for each abstract product How many specific products are there, they will be generated by each specific factory. This forms a corresponding relationship. Abstract factories and abstract products are expanded in two dimensions, forming a orthogonal The network reflects the scalability of the system, but for the framework, the system's product number extension is large, because expanding the type of product, means that the abstract factory and the specific factory code. The system style is increased Many, add a style, which means adding a specific factory that generates a new style of a new style for each product. It simply increases, and does not modify the code of the system frame. 3.2 Conceiver: constructor actually It is a commission relationship, that is, the client handed a series of functions or movements to the entrusted by the client. The client we called the header, the entrusted person is our constructor. The constructor is an abstract class, It defines all the prototypes of all the actions. Its subclass defines all of these actions, which forms a processing style. When we pass different styles of the directors, we achieve our extension, each expanded a constructor We redefine this set of operations, we also define a style. The commander does not need to care about this. The constructors and abstract factories are achieved different style creation models, and their difference is that The abstract factory is a set of products, each product is likely to be different, and the constructor is implemented for a set of operations. If we regard this set of operations as a product, we It can also be said that the constructor is realized by a single product level, and the abstract factory is implemented in the product set level. 3.3 Factors: The founder provides a unified approach to create a particular product. So this mode Abstract creators and abstract products, each particular creator corresponds to a specific product. This sounds like the constructor pattern, but they are very similar, a concrete builder Responsible is to correspond to a specific product. It is basically two distinct from the builders: a. Construction is a master from The directors need to save an example of a constructor to call the practical method implemented by the constructor. The factory method provides an interface and product life that generates an independent product does not generate a combination. B. Construction people pass one The group implements different functions to expand, that is, its extension is the function level, and the factory method is product level, that is, the extension in the factory method is based on the product. 3.4 prototype: prototype It did not emphasize the relationship between the products as the above three modes. It actually emphasizes the party that provides services, they are defined by the same function by the inheritance system. In this way, the expansion of the prototype does not have to be alarm. In fact The way in Java and it is easy to do, because the language itself supports such a clone function, through this function, the objects within the entire inheritance system can be unified, the framework only needs to grasp the unified reference to the base class, subclass It can be easily expanded. 3.5 Single case: I think the single case is completely replaced with global variables. I am more willing to call it skill than to say it. Some model mode is three points: a. A static private variable B. A private constructor C. A single-order function, and the function constructs this unique single case when the first call is called (call b-> assignment A-> Returns a). It is natural to have a lot of money. Cao Xihua read
2005-4-19 22:15:06