The observer pattern
The observer pattern is another behavioral pattern that is often used in networked system where a subject (the server) will notify some client. The iOS makes large use of this pattern through NSNotificationCenter
object.
Roles
The observer pattern creates dependence between a subject and observer so that the observer is notified in order to update their state each time the subject is modified.
This composition means that observer does not need to ask the current state of the subject. They only need to register to its notifications.
This pattern can be used when:
A state modification inside the object needs to update other objects dynamically
An object wants to prevent other objects without the need to know the type (without having to be high coupled with them)
We do not want to merge two objects into one
Design
The following diagram represents the UML class diagram of the observer pattern:
Participants
This pattern is composed of the following participants:
Subject
: This defines...