4 ms·
Academically the article may hold water, but I tend towards your thinking. There are just as many articles that will declare the values of loosely coupled syste
by themartorana 11y ago
Academically the article may hold water, but I tend towards your thinking. There are just as many articles that will declare the values of loosely coupled systems as there are for tightly-coupled. The truth is, most software of any size is a combination of the two.
In many cases, directly-related pieces should probably have a tight understanding of what's happening with their neighbor or ancestor or descendant, and delegates are great for this. But sometimes, I want my software to announce that certain things have happened, or completed, or whatever, and not care who, if anyone, is listening, and NSNotificationCenter is brilliant for this. For instance, a top-level UI feature like an indeterminate progress indicator doesn't need to know of every single bit of work being performed by lower levels of the software, and tightly coupling them - even along a delegate chain of some sort - is fraught with potential edge cases. Simply listening for start and end announcements means dozens of not hundreds of lines of code eliminated, and maintaining a crazy delegate chain unnecessary.
In any case, I've found this pattern extremely helpful and useful, and is one of my favorite bits of working with Objective-C (and now Swift).