PHP design pattern-mediation pattern-PHP Tutorial

Source: Internet
Author: User
Tags in domain zend framework
PHP design pattern: mediation pattern. We will introduce the mediation mode to you. the purpose of this mode is to encapsulate the interaction between a group of objects to prevent mutual interference between objects. The Mediator) colleagues (we will introduce the mediation mode to you. the purpose of this mode is to encapsulate the interaction between a group of objects to prevent mutual interference between objects. Mediator) serves as an intermediate aggregation point between Colleague objects.
Colleagues' objects should be loosely coupled to avoid an object pointing to another object explicitly. In the mediation by mode, when the relationship and dependency between objects conflict, we can use the mediation to coordinate the workflow between the coupled objects. the dependency can be established from a colleague to the mediation or from the mediation to the colleague, the dependency in both directions can be interrupted using abstractcolleags or AbstractMediator.


Target of mediators and colleagues

Objects are not isolated and must collaborate with each other to complete the task. Although the mediation mode can restrict the interaction between objects, it will become very difficult to compile the aggregated classes if abuse occurs. For example, the service in Domain-Driven Design is the mediation between entities. For another PHP-related example, the Zend_Form decoration and filtering functions can be regarded as a simple mediation between Zend_Form_Decorator and Zend_Filter instances. they all use the Zend_Validate object for verification.

When the mediator must listen to the events of a colleague object, it is usually implemented as an Observer to generate a blackboard object, written by some colleagues, and read by others. Events from colleagues are pushed to the mediation staff and then forwarded to other subscribe colleagues. colleagues do not need to know each other. This architecture is successfully used for the Dojo JavaScript library released with the Zend Framework. Another advantage of this mode is that the changes of objects are included in the calculation method. you can configure different mediators to achieve this goal, but instantiating the objects will be a loose operation, the relationships between containers and factories are scattered. Participants:

◆ Collegou: it focuses on its responsibilities. it only communicates with one Mediator or AbstractMediator.

◆ Mediator: works with multiple Colleagues.

◆ AbstractMediator and AbstractColleague: an optional interface for real decoupling of these roles. There may be more than one role AbstractColleague.

The following code implements a form input filtering process, similar to the Zend_Form_Element function.


Colleagues' objects should be loosely coupled to avoid an object pointing to another object explicitly. In the mediation by mode, when the relationship and dependency between objects conflict, we can use the mediation to coordinate the workflow between the coupled objects. the dependency can be established from a colleague to the mediation or from the mediation to the colleague, the dependency in both directions can be interrupted using abstractcolleags or AbstractMediator.
Target of mediators and colleagues
Objects are not isolated and must collaborate with each other to complete the task. Although the mediation mode can restrict the interaction between objects, it will become very difficult to compile the aggregated classes if abuse occurs. For example, the service in Domain-Driven Design is the mediation between entities. For another PHP-related example, the Zend_Form decoration and filtering functions can be regarded as a simple mediation between Zend_Form_Decorator and Zend_Filter instances. they all use the Zend_Validate object for verification.
When the mediator must listen to the events of a colleague object, it is usually implemented as an Observer to generate a blackboard object, written by some colleagues, and read by others. Events from colleagues are pushed to the mediation staff and then forwarded to other subscribe colleagues. colleagues do not need to know each other. This architecture is successfully used for the Dojo JavaScript library released with the Zend Framework. Another advantage of this mode is that the changes of objects are included in the calculation method. you can configure different mediators to achieve this goal, but instantiating the objects will be a loose operation, the relationships between containers and factories are scattered. Participants:
◆ Collegou: it focuses on its responsibilities. it only communicates with one Mediator or AbstractMediator.
◆ Mediator: works with multiple Colleagues.
◆ AbstractMediator and AbstractColleague: an optional interface for real decoupling of these roles. There may be more than one role AbstractColleague.
The following code implements a form input filtering process, similar to the Zend_Form_Element function.
/*** Colleague. */class NullFilter implements Filter {public function filter ($ value) {return $ value? $ Value: ;}/ ***** Colleague. */class HtmlEntitiesFilter implements Filter {public function filter ($ value) {return htmlentities ($ value );}}
___ FCKpd ___ 2
Original article name: Practical Php Patterns: Mediator author: Giorgio
Filters;

Protected: We will introduce the mediation mode. the purpose of this mode is to encapsulate the interaction between a group of objects to prevent mutual interference between objects. the Mediator is on the colleaguate object) serves as an intermediate aggregation point.


Colleagues and objects should be loosely coupled to avoid

Pipeline (Mediator) in the colleague object (...

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.