Saturday, December 24, 2011

A paragraph about Observer pattern in Objective-C


Another way of making objects talk to each other in Objective C is using Observer pattern. In this pattern, an object can send its customized notification to the notification centre. Then it is the notification centre that notifies the objects who has registered for that particular notification. This can be for many reasons. For instance, an object working with model layer might think that it would be of other objects’ interest to know that it has created a new NSManagedObject in the model layer. This can be very useful when for example a table view, showing that data, needs to know when to reload itself. From my point of view, one of the most intriguing aspects of observer pattern is the fact that there is no relationship needed between the sender and the receiver of a notification. In addition, a single notification can be observed by many objects at the same time.

No comments:

Post a Comment