Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>basically Observer pattern says that there is an object that is a subject of interest of other objects.<br> Let's say for example, we have a <code>Kid</code> object, who has properties such as <code>MathGrade</code>, <code>GeographyGrade</code> etc..<br> Now, objects <code>Mother</code>, <code>Father</code>, <code>Principal</code> are all interested in changes of the <code>Kid</code> object's properties.<br> They have basically 2 options- </p> <ol> <li><p>coming up to the <code>Kid</code> every day and ask 'has your <code>MathGrade</code> changed?' 'has your <code>GeographyGrade</code> changed?' etc.<br> that approach is not very efficient. </p></li> <li><p>they can just say to the <code>Kid</code>- 'OK, here's my number- call me if your <code>MathGrade</code> changes'.<br> that is essentially the Observer pattern: whoever is interested in changes to the object registers themselves with that object, and is guaranteed to be notified whenever a change occurs. </p></li> </ol> <p>And if to get back to the programming world- you would have an <code>IGradeObserver</code> interface, which will declare a <code>MathGradeChanged(int newGrade)</code>, <code>GeorgraphyGradeChanged(int newGrade)</code> functions.<br> The classes <code>Mother</code>, <code>Father</code>, and <code>Principal</code> would implement <code>IGradeObserver</code>.<br> Now, the <code>Kid</code> class will have a list of <code>IGradeObservers</code>, and a <code>RegisterObserver(IGradeObserver observer)</code> method. </p> <p>Now, whenever a grade changes, the <code>Kid</code> class would iterate through its Observers list, and notify them of that change. </p> <p>callbacks and event listeners are one way of implementing this pattern.<br> I suggest googling this, I've found a couple of interesting guides myself (<a href="http://code.pavankumar.info/archives/85" rel="nofollow">here</a>, and <a href="http://elope.wordpress.com/2006/04/07/tutorial-on-observer-pattern-2/" rel="nofollow">here</a>).<br> I'm sure you can find some others as well, also pertaining to the programming language of your choice.<br> good luck. </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. This table or related slice is empty.
    1. 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