Definition: 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.
Function: Search the database and send it in various ways when there is a need to publish the data.
The observer model can certainly be very good to achieve the above requirements, no matter how many ways, as long as the addition of multiple inherited Itransfer interface of the derived c
The observer model is one of the more commonly used patterns and the basis for other common patterns, such as the MVC pattern, which is a model based on observer mode.
In the Java language, the implementation of observer mode is very simple, that is, let the observer inherit the observable class, and let the
Tag: Java logs this dependent for Code mode packThe observer pattern for Java design patternsHave always wanted to write a study of the Observer Pattern Summary no opportunity, today learning to block the principle of the queue to see in the implementation of the producer consumer when the notification mode, is the so-called observer mode, just by the way to tidy
The actors involved in the Observer pattern are:
Abstract theme (Subject) role: Abstract theme Roles Keep all references to observer objects in a cluster (such as a ArrayList object), each subject can have any number of observers. Abstract topics provide an interface for adding and removing observer objects, and abstract theme roles are also called abstract-
Observer pattern: A one-to-many dependency between objects that allows multiple observer objects to simultaneously monitor a Subject object (observed).
So that when the state of an object changes, all objects that depend on it are notified and changed accordingly.There are many ways to implement the Observer pattern: The pattern must contain two roles of the
What is the observation of the pattern
When multiple observers want to observe the same subject object at the same time, the subject matter is the change of the state of our observer, and the way in which the observer can recall itself is old and updated.Implementation steps: First: Define an observer interface The second ob
Observer Pattern Definition:
Define a one-to-many dependency between objects so then one object changes state, all its dependents AER notified and Updated automatically.
Defines a one-to-many dependency between objects so that when an object changes state, all objects that depend on it are notified and automatically updated.
as shown in the figure above (intercepted from the head Patterns), it consists of four main parts:
1. Subject the observed per
Use
Observer Mode (Observer)
The 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 a
In the previous section we explained some of the knowledge of the observer pattern and customized the classic code of the Observer Pattern, (Teleport: Design mode go through--observer mode (above))
This article briefly introduces the observer Pattern implementation code that comes with the JDK.
For the
The code looks like this:
Copy Code code as follows:
The abstract class of the person being observed
Class observed implements splsubject{
protected $_name;
protected $_observers;
Instantiated to generate an observer objectPublic Function __construct () {$this->_observers = new Splobjectstorage ();}
Add Observer ObjectPublic function Attach (Splobserver $
Introduced
The observer pattern, also known as the Publish subscription model (Publish/subscribe), defines a one-to-many relationship in which multiple observer objects listen to a Subject object at the same time, and the subject object's state changes to notify all observer objects so that they can automatically update themselves.
Benefits of using the
Java to a certain extent, it is inevitable to encounter the concept of design pattern, understanding design patterns, will make their own Java interface or abstract class application have a deeper understanding. Design Patterns in the Java medium-sized system applications, follow a certain programming mode, to make their own code easy to understand, easy to communicate, OBSERVER (Observer) mode is a more co
Java to a certain extent, it is inevitable to encounter the concept of design pattern, understanding design patterns, will make their own Java interface or abstract class application have a deeper understanding. Design Patterns in the Java medium-sized system applications, follow a certain programming mode, to make their own code easy to understand, easy to communicate, OBSERVER (Observer) mode is a more co
Observer Pattern)
Overview
The observer mode is used to establish a dependency between an object and an object. When an object changes, other objects are automatically notified, and other objects are responded accordingly. In the observer mode, the changed object is called the observation object, and the notified object is called the
The Observer pattern (Observer) defines a one-to-many dependency that allows multiple observer objects to listen to a Subject object at the same time. When the subject object changes in state, all observer objects are notified so that they can automatically update themselves. For example, when a button has multiple lis
Observer Design Pattern
Observer mode: defines a one-to-many dependency between objects. When the status of an object changes,All objects dependent on it are notified and automatically updated.
In this definition, the first keyword is dependency, which is a type of relationship between classes. Dependency refers to dependency between one class and another class, generally, objects are transmitted in the met
For more information about RxJava in observer mode, see rxjava for more information.Preface what is RxJava
RxJava-Reactive Extensions for the JVM-a library for composing asynchronous and event-based programs using observable sequences for the Java VM.
The above is the introduction of RxJava on Github, which roughly means,For the responsive extension Implementation of JVM (Java Virtual Machine), a library that uses an observed sequence on Java VM to Im
Observer mode, also known as publish-subscribe, MVC pattern, etc. Popular point, for example, stocks, a lot of people pay attention to a stock, send a person to observe the situation of the stock, a change (observation), notify all the people who ordered the news.While our common MVC pattern, v refers to the view-view, M refers to the model-model, a bit like the observer pattern, the data in the model, a ch
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.