Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>How does the Observer pattern work ?</p> <ul> <li>Observable objects are "watched" by Observer objects</li> <li>When an Observable is modified, it notifies all of its observers a change has been made, for example by calling their "update" or "notify" function (or whatever)</li> </ul> <p>So, in terms of <strong>signals</strong> and <strong>slots</strong>. The basics are that you connect signals to slots, which will be called each time the signal they're connected to is emitted.</p> <p>You will find that it is very easy to use in the Observer pattern : just create a signal in the Observable that will be connected to the slot of each Observer used to update it.</p> <p>in case of a change in the Observable. Instead of looping through the list of all your observers, and calling their <code>update</code> method one after another, just emit the signal. The corresponding slots will magically be called.</p> <p>To go further, you could for example have a slot in the Observable, connected to a signal that an Observer will emit to tell the Observable it has to be noticed in case of changes...</p> <p>Can't get you a fully working example code since I never used <code>Boost::signals2</code>, but you should take a look at <a href="https://stackoverflow.com/questions/10418582/how-do-i-use-boostsignals-to-implement-the-observer-pattern" title="How do I use boost::signals to implement the observer pattern?">How do I use boost::signals to implement the observer pattern?</a> and <a href="https://stackoverflow.com/questions/2225162/observer-design-pattern-in-c%20">Observer design pattern in C++</a> to get you going :)</p>
    singulars
    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.
 

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