Reputation: 19507
Is it bad form to use NSNotifications back and forth all over my app?
Upvotes: 0
Views: 185
Reputation: 89
Typically you'd want to use notifications only when more than one object may want to be informed of the event. When there's only one interested object, use the delegate pattern. There's an excellent overview in the Cocoa Fundamentals guide under "Cocoa Design Patterns."
Upvotes: 0
Reputation: 21893
The beauty of NSNotification is that it allows cause and effect to be decoupled. A NSNotification broadcaster doesn't care who's listening, or what they do once they get it. An NSNotification consumer doesn't care who sent the message. That's a GOOD thing.
However, there ARE times you want cause and effect to BE coupled. At that time, you want to use a direct method call between to view controllers, or Key-Value Observing, or something more concrete.
I wouldn't make a hard-and-fast rule out of it, but if you're having trouble keeping mental track of all your NSNotifications, that's probably too many.
Upvotes: 4
Reputation: 27285
Not per se, but it would probably be a symptom of some underlying design problem.
Upvotes: 1