Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
The biggest weakness of the Notification pattern is that class designers must anticipate the need for notifications. The developers at Apple were able to anticipate that programmers would want to do something special when a window is about to be closed and provided the NSWindowWillCloseNotification. There is a trade-off. Posting a notification takes some processor time even when there are no registered observers for the notification. It’s not practical to post a notification for every single application state change. Therefore, designers must find a balance between too many and too few notifications.
The Delegates pattern in Chapter 15 is closely related to the Notification pattern. In fact, Cocoa classes use the Delegate pattern in many of the same cases that notifications are used. As a general rule, use Notifications when there are potentially many objects that may observe the notification. Use the Delegates pattern when exactly one object is given an opportunity to influence or react to changes as they are happening.