Notes on the big talk design model (9)

Source: Internet
Author: User

Chapter 2 intermediary Mode

    • Mediator), Uses an intermediary object to encapsulate a series of object interactions. The intermediary makes the objects do not need to be explicitly referenced to each other, so that the coupling is loose and the interaction between them can be changed independently.
    • The intermediary mode is easy to apply in the system and misuse in the system. When the system has a complex multi-to-many interaction object group, do not rush to use the intermediary mode, but first reflect on whether your system is properly designed.
    • Since we abstract how objects collaborate, we use mediation as an independent concept and encapsulate it in an object, in this way, the objects of interest will be transferred from the actions of the objects themselves to the interactions between them, that is, viewing the system from a macro perspective.
    • The intermediary mode is generally used when a group of objects communicate in a well-defined but complex manner, and you want to customize a behavior distributed in multiple classes, and do not want to generate too many child classes.

 

Chapter 1 metadata sharing

    • Flyweight), Using the sharing technology to effectively support a large number of fine-grained objects.
    • The metadata mode avoids the overhead of a large number of similar classes. InProgramSometimes, a large number of fine-grained class instances are generated to represent data. If we can find that these instances are basically the same except several parameters, sometimes we can reduce the number of classes to be instantiated by the same means. If you can move those parameters out of the class instance and pass them in when calling the method, you can greatly reduce the number of individual instances by sharing them.
    • If an application uses a large number of objects, and a large number of these objects cause a large storage overhead, you should consider sharing them. In addition, most states of objects can be external states, if you delete the external state of an object, you can replace many groups of objects with a relatively small number of shared objects. In this case, you can consider using the metadata mode.

 

Chapter 1 Interpreter Mode

    • Interpreter mode (Interpreter)To define a language, a representation of its method, and an interpreter. This interpreter uses this representation to explain sentences in the language.
    • If a specific type of problem occurs frequently enough, it may be worthwhile to express each instance of the problem as a sentence in a simple language. In this way, an interpreter can be built to solve the problem by interpreting these sentences.
    • When a language needs to be interpreted and executed, and you can represent sentences in the language as an abstract syntax tree, you can use the interpreter mode.
    • The advantage is that you can easily change and extend the method, because this mode uses classes to represent method rules, you can use inheritance to change or extend the method. It is also easier to implement grammar, because the implementation of classes on each node in the definition abstract syntax tree is similar in general, and these classes are easy to directly write.
    • There are also deficiencies in the interpreter mode. The Interpreter mode defines at least one class for each rule in the grammar, so the syntax containing many rules may be difficult to manage and maintain. We recommend that you use other technologies such as syntax analysis programs or compilation generators to process the syntax when it is very complex.

 

Chapter 4 visitor Mode

    • Visitor mode (visitor)Indicates an operation that acts on each element in an object structure. It allows you to define new operations that act on these elements without changing the classes of each element.
    • Visitors are suitable for systems with relatively stable data structures. It frees the coupling between the data structure and the operations acting on the structure, allowing the operation set to evolve relatively freely.
    • The visitor mode aims to separate processing from the data structure.
    • The advantage of the visitor mode is that it is easy to add new operations, because adding new operations means adding a new visitor. The visitor mode aggregates relevant behaviors into a visitor object.
    • The disadvantage is that it is difficult to add new data structures.

 

 

------------------------------------------------

Use word2007 to publish a video. The video is not displayed. Go to the independent blog to view the complete content.Article!

Modify and add content of the article only in the independent blog!

My independent blog: kiddie-Http://www.zyblog.net/

Link to this article:Http://www.zyblog.net/post-80.html

You are welcome to reprint it. Please indicate the source of this article.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.