PHP design pattern-Observer pattern

Source: Internet
Author: User
PHP design pattern-Observer pattern
 Observers [] = $ observer;} // The notification event has occurred. other observers update their own logic function notify () {foreach ($ this-> observers as $ observer) {$ observer-> update () ;}}// Event class Event extends EventGenerator {function trigger () {echo "Event
\ N "; // the operations performed by the Observer after the event occurs $ this-> Y ();}} // Observer 1 class Observer1 implements \ Tools \ Observer {function update ($ event_info = null) {echo "logic 1
\ N ";}}// Observer 2 class Observer2 implements \ Tools \ Observer {function update ($ event_info = null) {echo" logic 2
\ N ";}}$ event = new Event; $ event-> addObserver (new Observer1); // inject observer 1 $ event-> addObserver (new Observer2 ); // inject the Observer 2 $ event-> trigger (); // trigger the event

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.