Interpreter of design pattern, mediator mode

Source: Internet
Author: User

Both the interpreter mode and the mediator mode are behavioral patterns, because they are used less, not too much interpretation, introduce the related concepts for reference.

The interpreter pattern is a bit of a "compiler" concept, like a super-simple compiler, and it's not hardware-independent, it's designed to define the grammar of the language (using code in the prescribed format and syntax) and then create an interpreter to interpret the sentences in that language.

In GOF's book, it is noted that if a particular type of problem occurs at a sufficiently high frequency, it may be worthwhile to describe each instance of the problem as a sentence in a simple language. This allows you to build an interpreter that solves the problem by interpreting these sentences. And it works best when the grammar is simple and efficiency is not a key issue-this is the context in which the interpreter pattern applies.

Put an interpreter structure class diagram bar, as a reference, here is not a deeper interpretation.

The mediator pattern is defined as using a mediation object to encapsulate a series of object interactions. Mediators do not need to explicitly cross-reference each other, so that they are loosely coupled, and can independently change their interaction between the simple point, the original two directly referenced or dependent objects apart, adding a "mediation" object in the middle, so that the object of both ends and "mediation" object reference or dependency. Of course not all objects need to be added to the "mediation" object. If the relationship between the objects is at a glance, the addition of the mediator is "superfluous".

Look at the part of the mediator model.
1) abstract Mediator (mediator) Role: Abstract Mediator role defines a unified interface for communication between colleague roles.
2) Specific mediator (concrete mediator) role: The specific mediator role enables collaborative behavior by coordinating the roles of colleagues. To do this, it needs to know and reference each colleague role.
3) Co-worker (colleague) role: each colleague role is aware of the specific mediator role, and when communicating with other colleague roles, be sure to collaborate through the mediator role.
Class diagram from the book "Design Mode":

Remember what three layers of MVC are widely used? The model layer, the presentation layer (View), and the control layer (control\mediator). The control layer is the mediator between the presentation layer and the model layer. Generally speaking, MVC is also considered as an application of the mediator pattern in the framework design.

Interpreter of design pattern, mediator mode

Related 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.