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
First, what is the observer mode? The observer mode refers to a situation where multiple objects know the changes of data in an object. For example, almost all colleges and universities now have part-time center for college students, that is, part-time intermediary, the part-time center notifies all members of the part-time information every day. This is an observer
The observer pattern, also called the (publish-subscribe) pattern, is a type of behavioral pattern that defines a one-to-many relationship, which is handled when multiple observers simultaneously monitor the changes that occur to the observed.
No more nonsense, today to share about the Observer mode related content. No more nonsense, then go directly to the code instance.
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
Android Design Pattern source code parsing: ListView observer pattern, androidlistviewAndroid Design Pattern source code parsing-Observer Pattern
This article analyzes the observer mode in the source code parsing of Android Design PatternsAndroid: 2.3ANALYST: Mr. Simple, analysis status: incomplete, Proofreader: Mr. Simple, proofreader Status: Not started
1. I
An analysis of the observer model
Simply put, the Observer pattern defines a one-to-many dependency that allows one or more observer objects to monitor a subject object. Changes in the state of such a Subject object can inform all those observer objects that depend on the object so that 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
The observer mode is the behavior mode of objects. It is also called the publish/subscribe mode, Model-View mode, and source-listener (Source/listener) mode) mode or dependents mode. The observer mode defines a one-to-many dependency, allowing multiple observer objects to listen to a topic object at the same time. When the status of this topic object changes, it
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 mode:
The Observer Pattern Defines a one-to-define dependency between objects so that when one object changes state, all of its dependents are notified and updated automatically. (The Observer mode defines a one-to-many dependency between objects, so that every time an object changes its state, all objects dependent on it will be notified and automatical
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
Observer mode
/*** Define the Observation interface*/Interface Subject{Public Function Attach ($Observer); Add ObserverPublic Function Detach ($Observer); Kick out The ObserverPublic function Notify (); Notify observers when conditions are metPublic Function subjectstate ($Subject); Observation conditions}/*** The specific implementation of the observation class
Observer Mode
Observer mode: defines a one-to-many dependency, so that multiple observer objects can listen to a subject object at the same time. When the State of the subject object changes, all observers are notified. When an object needs to change other objects at the same time and does not know how many objects need to be changed, you should consider using t
Observer mode-Java Design Mode
Observer mode definition: defines one-to-many dependencies between objects. In this way, when an object changes its state, all its dependent persons will receive notifications and update them automatically. See:
The observer design pattern is also called the publish-subscribe pattern.It can also be called: publisher + subscriber =
The Observer (Observer) mode, also known as publish-subscribe (publish/subscribe) mode, is a four-person group (GoF, that is, Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides) is presented in the 1994 co-author of the design pattern: The basics of reusable object-oriented software (see 293-313 pages in the book). Although this pattern has a long history, it is still widely used in a variety of s
Introduced
The Observer pattern defines a one-to-many dependency on an object, so that when an object changes state, all its dependents are notified and automatically updated!
Design principles
In the Observer pattern, the status of the subject and the number of observers are changed. With this pattern, you can change objects that depend on the subject's state without having to change the subject. --Identif
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 fou
Observer mode highlights:
1. The observer mode defines the one-to-many relationship between objects.
2. The topic (that is, the observer) uses a common interface to update the observer.
3. The observer and the observer are loosely
Original source: http://www.cnblogs.com/java-my-life/archive/2012/05/16/2502279.html
In Dr Shanhong's "Java and Schema" book, this describes the Observer (Observer) pattern:
The observer pattern is the behavior pattern of the object, also known as the Publish-subscribe (publish/subscribe) mode, model-view (model/view) mode, source-listener (Source/listener) mo
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.