Structure mode - experience

xiaoxiao2021-03-06  79

The structural type emphasizes that 1 1> 2 is to make full use of existing classes or objects, through reasonable assembly, achieving the effect of unexpected (in fact, it is an urgent need to reach).

1.Adapter. This substantially existing system will be used more or less. Because, a part of the structure is based on its own system, and on the other hand, the platform library, MFC .NET, etc. are available. To use these two, you must use the adapter mode to pull. This is mainly from classification adaptation and object adaptation. That is, inheritance or combination, it is almost. It is like a class that can calculate the addition or decrease of two values. Then there is a class that calculates a variance, you can use this class to calculate the variance. 2. Bridge mode. This model industry is the most use of it uses it to do platform-independent design. We generally have an abstract and realization concept when it is designed. Abstract is for different implementation, flexibility is this pull. However, each implementation is inseparable from the platform characteristics. The most obvious is to draw or network isotropic. Absolutely universal. In this way, Bridge mode has been subjected to secondary abstraction. It is assumed that the upper interface is unchanged, the implementation of the interface is abstract, using this layer to realize the upper interface, this way, no matter which platform, as long as it is realized, The upper layer interface is not cared. In fact, this is contained in OO design, very famous "interface inversion" principle. In the past, discussions will find that it is the upper layer depending on the lower layer. This is actually very dangerous. If an upper layer is implemented in four underlying, then this upper layer is revised by four places to modify the danger. Unstability is high. 3. Combined mode. It is emphasized that dynamic management containers. Adding or deleting elements in the container, and these elements have similar responsibilities, otherwise this mode is not applicable. Avoid users to care about each subtle element, especially when you can reflect the father and child relationship, this model is actually a layer of encapsulation. 4. Decorative pattern. This mode is important and fully reflects the dynamics and flexibility of the pattern. In fact, for an existing system, you can dynamically add new duties. What is a gratifying thing. It's like a class that has been calculated has been processed. I need a class now to record this result and process. So, I need to inherit this class, then use existing methods to process calculations, add a job, write process and results into a file. 5. Share element mode. The mode has been used or the designed transition will cause a problem, called a sub-explosion or object explosion. Although the performance is now unprecedented, blind use, especially large projects, rational use of resources is not necessary, and at least it is also an embodiment of itself. The place I understood by Flyweight is mainly a large number of objects generated, and there is no internal state when practical use. Usually a class generates a number of objects, and the differences between these objects have different internal states. Each state is an instant snapshot of each class, and each object will choose different behavior to go down according to the current state. And if this class generated object is not in this statement, then even the external object is first run with a method of object A, and the object B is used to perform the remaining method, it is possible. Under this premise, Flyweight can be used. Anyway, no matter how many are the same, it is better to generate one, this is why he can save space. Usually we will make these objects, take it, just record his station symbol instead of each called his object, not his copy (what we discussed with a copy, the prototype mode is not pulled)

转载请注明原文地址:https://www.9cbs.com/read-94341.html

New Post(0)