Design Patterns-Observer patterns

Source: Internet
Author: User

/**     * Observer mode     *      Overview: * During     the  software build process, we need to establish a "notification dependency" for certain objects--a change in the state of an object (the target object),  All dependent objects (Observer objects) will be notified. If such dependencies are too tight, the software will not be able to withstand changes very well.     *  using object-oriented technology, you can weaken this dependency and form a stable dependency relationship.     *  to achieve loose coupling of software architecture.     *  Define a one-to-many dependency between objects, and when the state of an object changes,  all objects that depend on it are notified and automatically updated.     *       * Achieve effect     *  1. Using object-oriented abstraction, the Observer pattern allows us to independently change the target and the observer, so that  the dependency between them is loosely coupled.     *  2. When a target sends a notification, there is no need to specify the observer, and the notification (which can carry notification information as an argument) is automatically propagated.     *  observers themselves decide whether to subscribe to notifications. The target object is ignorant of this.     *  3. The event in C #. The delegate acts as an abstract observer interface, while the object that provides the event acts as the target object, and the  delegate is a more loosely coupled design than the abstract observer interface. * * *       Applicable scenario:     *  1. When an abstract model has two facets, one aspect depends on the other.     *  encapsulate the two in separate objects so that they can be changed and reused independently of each other.     *  2. When a change to an object needs to change other objects at the same time, it is not known how many objects need to be changed.     *  3. When an object must notify other objects, it cannot assume that other objects are who.     *  In other words, you don't want these objects to be tightly coupled     *  http://www.diyibk.com/post/97.html    
* * Design principles * Work hard for loosely coupled design between interacting objects;

Design mode-Observer mode

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.