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.