A summary of the observer pattern

Source: Internet
Author: User

OBSERVER (Observer Mode): Defines a one-to-many dependency between objects so that when the state of an object changes, all objects that depend on it are notified and refreshed automatically.

observer-want to know our company's latest mm intelligence. Join the company's MM intelligence mail group on the line, Tom is responsible for collecting intelligence, he found that the new information without a notice to us, directly to the Mail group, we as subscribers (observers) can receive information in a timely manner


The principles involved are:

Strive for loosely coupled design between interacting objects


Class Diagram:


Role of observer mode:
Subject (observed)
The object being observed. When the state that needs to be observed changes, all observer objects in the queue need to be notified. Subject need to maintain (add, delete, notify) a list of queues for an observer object.
ConcreteSubject
The concrete realization of the observed. Contains some basic property states and other operations.
OBSERVER (Observer)
Interface or abstract class. When the state of the subject changes, the Observer object is notified via a callback function.
Concreteobserver
The specific implementation of the observer. After being notified, some specific business logic processing will be completed.


Also, Java's JDK has a similar API that we can use.

Typical example:, the user interface can be as an observer, business data is the Observer, the user interface to observe the changes in business data, the discovery of data changes, is displayed on the interface. One of the principles of object-oriented design is that each class in the system focuses on one function, rather than on other aspects. An object only does one thing and does it well. The Observer pattern defines a clear boundary between the modules, improving the maintainability and reusability of the application. The observer design pattern defines a one-to-many dependency between objects, so that when the state of an object changes, all objects that depend on it are notified and refreshed automatically.


Personal understanding: The world model in AGENT2D is probably designed to be the observer pattern. Every change in the world model will update some of the content inside. Each player is given a model of the world he observes. Then, according to the world model to judge processing, using machine learning algorithm to process this information, the final implementation of good decisions.



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.