Simple subscriber Mode

Source: Internet
Author: User
Lynda assumes that there is a system service and several modules need to use the service. components can subscribe to this service or message and notify all modules through system broadcast. None? Php subscription publishing Mode Interface Definition and message transmission classDispatcher {monitor publicstatic $ listenersarray (); protectedfunction _ constru

Lynda assumes that there is a system service and several modules need to use the service. components can subscribe to this service or message and notify all modules through system broadcast. None? Php // subscription publishing Mode Interface Definition and message passing class Dispatcher {// monitoring public static $ listeners = array (); protected function _ constru

Lynda
Suppose there is a system service, and several modules need to use the service. The component can subscribe to this service or message and notify all modules through system broadcast. <无>
  DoSomething () ;}} class Service {protected $ name = ''; public function _ construct ($ name) {$ this-> name = $ name ;} // trigger the public function doSomething () {echo sprintf ("% s has something happened. \ n ", $ this-> name); Dispatcher: publish ($ this) ;}} class Component {protected $ name = ''; public function _ construct ($ name) {$ this-> name = $ name;} public function doSomething () {echo sprintf ("% s did something. \ n ", $ this-> name) ;}$ serviceA = new Service (" ServiceA "); $ componentA = new Component (" componentA "); $ componentB = new Component ("componentB"); $ componentC = new Component ("componentC"); Dispatcher: subscribe ($ serviceA, $ componentA); Dispatcher :: subscribe ($ serviceA, $ componentB); Dispatcher: subscribe ($ serviceA, $ componentC); // trigger an Action $ serviceA-> doSomething (); // output // ServiceA something happened. // componentA did something. // componentB did something. // componentC did something.

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.