Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Observer pattern
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
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!
==Structure== ===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. ===UML class diagram=== [[File:Observer w update.svg|none|thumb|500x500px|[[Unified Modeling Language|UML]] class diagram of Observer pattern]]
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
Observer pattern
(section)
Add topic