Big talk design Pattern---observer pattern

Source: Internet
Author: User

  Observer pattern: Defines a one-to-many dependency that allows multiple observer objects to listen to a Subject object at the same time. This subject object notifies all observer objects when the state changes, enabling them to automatically update themselves.


You should consider using the observer pattern when an object change needs to change other objects at the same time, and it does not know how many objects need to be changed.

  An abstract model has two aspects, one on the other hand, and the observer pattern allows the two to be encapsulated in separate objects to be independently changed and reused.

The work done by the observer pattern is actually decoupling. Let both sides of the coupling rely on abstraction, rather than relying on specifics. So that their changes will not affect the other side of the change.

a delegate is a type of reference method. Once a delegate has been assigned a method, the delegate will have exactly the same behavior as the method. The delegate method can be used like any other method, with parameters and return values. A delegate can be thought of as an abstraction of a function, a function's ' class ', and an instance of a delegate representing a specific function.

  A delegate can carry multiple methods, all of which are recalled sequentially, and the methods that are carried by the delegate object do not need to belong to the same class.

All methods carried by a delegate object must have the same prototype and form, that is, have the same parameter list and return value type.

Big talk design Pattern---observer pattern

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.