Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The standard implementataion of the observer pattern to be found in Smalltalk would be the <code>#changed</code>/<code>#update</code> mechanism.</p> <p>It goes like this:</p> <pre><code>subject addDependent: anObserver. subject changed. </code></pre> <p>and then <code>anObserver</code> gets send <code>#update</code>:</p> <pre><code>MyObservingObject&gt;&gt;update "I got called in a #changed chain" super update. self doUpdatingStuff </code></pre> <p>You can have finer control using <code>#changed:</code> and <code>#update:</code> (note the colon):</p> <pre><code>subject addDependent: anObserver. subject changed: subject. </code></pre> <p>and</p> <pre><code>MyObservingObject&gt;&gt;update: anObject "I got called in a #changed: chain" super update: anObject. self doUpdatingStuffWith: anObject </code></pre> <p>However, it is commonly found to use a symbol to indicate what changed:</p> <pre><code>subject addDependent: anObserver. subject changed: #myNumbers. </code></pre> <p>and</p> <pre><code>MyObservingObject&gt;&gt;update: anObject "I got called in a #changed: chain" anObject == #myNumbers ifTrue: [ self doUpdatingStuffForNumbers. ^ self "inhibits the super"]. super update: anObject. </code></pre> <p>When you look at <a href="http://www.squeak.org">Squeak</a> or <a href="http://www.pharo.org">Pharo</a>, you'll find at least three other Observer implementations:</p> <ul> <li>The event handling for Morphic (see <code>Morph&gt;&gt;#on:send:to:</code>)</li> <li>A similar, more general event handling mechanism, see <code>Object&gt;&gt;#when:send:to:</code> and <code>Object&gt;&gt;#triggerEvent:</code></li> <li>the <em>Announcements</em> framework, encapsulating messages between subject and observer in classes.</li> </ul> <p>You can find a <a href="https://www.hpi.uni-potsdam.de/hirschfeld/trac/SqueakCommunityProjects/wiki/signals#FeatureComparison">comparison</a> of these at the <a href="https://www.hpi.uni-potsdam.de/hirschfeld/trac/SqueakCommunityProjects/wiki/signals">Signals project</a>, another implementation, but inspired by Qt.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload