Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Observer pattern
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===UML class and sequence diagram=== [[File:w3sDesign Observer Design Pattern UML.jpg|frame|none|A sample UML class and sequence diagram for the observer design pattern. <ref>{{cite web|title=The Observer design pattern - Structure and Collaboration|url=http://w3sdesign.com/?gr=b07&ugr=struct|website=w3sDesign.com|access-date=2017-08-12}}</ref>]] In this [[Unified Modeling Language|UML]] [[class diagram]], the <code>Subject</code> class does not update the state of dependent objects directly. Instead, <code>Subject</code> refers to the <code>Observer</code> interface (<code>update()</code>) for updating state, which makes the <code>Subject</code> independent of how the state of dependent objects is updated. The <code>Observer1</code> and <code>Observer2</code> classes implement the <code>Observer</code> interface by synchronizing their state with subject's state. The [[Unified Modeling Language|UML]] [[sequence diagram]] shows the runtime interactions: The <code>Observer1</code> and <code>Observer2</code> objects call <code>attach(this)</code> on <code>Subject1</code> to register themselves. Assuming that the state of <code>Subject1</code> changes, <code>Subject1</code> calls <code>notify()</code> on itself. <code>notify()</code> calls <code>update()</code> on the registered <code>Observer1</code> and <code>Observer2</code>objects, which request the changed data (<code>getState()</code>) from <code>Subject1</code> to update (synchronize) their state.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)