<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: In Defense of Observers</title>
	<atom:link href="http://losingfight.com/blog/2007/04/26/in-defense-of-observers/feed/" rel="self" type="application/rss+xml" />
	<link>http://losingfight.com/blog/2007/04/26/in-defense-of-observers/</link>
	<description>try the veal</description>
	<lastBuildDate>Thu, 24 Dec 2009 13:45:24 -0800</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Frank</title>
		<link>http://losingfight.com/blog/2007/04/26/in-defense-of-observers/comment-page-1/#comment-412</link>
		<dc:creator>Frank</dc:creator>
		<pubDate>Tue, 01 May 2007 15:54:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.losingfight.com/blog/2007/04/26/in-defense-of-observers/#comment-412</guid>
		<description>Why don&#039;t you use a protocol to implement the observer?  That way you don&#039;t need to inherit from it, and you can &quot;mix&quot; it in with existing classes...</description>
		<content:encoded><![CDATA[<p>Why don&#8217;t you use a protocol to implement the observer?  That way you don&#8217;t need to inherit from it, and you can &#8220;mix&#8221; it in with existing classes&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andy</title>
		<link>http://losingfight.com/blog/2007/04/26/in-defense-of-observers/comment-page-1/#comment-411</link>
		<dc:creator>Andy</dc:creator>
		<pubDate>Tue, 01 May 2007 03:57:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.losingfight.com/blog/2007/04/26/in-defense-of-observers/#comment-411</guid>
		<description>@patrick: Thanks for the info about KVO. I&#039;d love to take it for a spin as soon as I have a project that allows me to do that.

Also, I don&#039;t think bloggers were too rough on the Cocoa features. Brent and others pointed out some gotchas and limitations of the technologies, but I don&#039;t think any of them meant: &quot;these are bad technologies.&quot; In fact, I remember some praise of bindings, and rightfully so.

@Stephane: The pattern you describe with the anchorman and the news is the Moderator pattern, not the Observer pattern. If that&#039;s your model, then (I think) you would be correct to use NSNotificationCenter. In the Observer pattern, the observer actually cares about one specific subject (the person actually making the news in your example, as opposed to the anchorperson). My point was, in that model, NSNotificationCenter is not appropriate. Also note that the news example is a many-to-many relationship. Many people are making the news, and many people are listening to it.

@Nathan: I will admit I can be a bit dogmatic about design patterns, and anal about coding standards. You are correct that the notifications are their own design pattern. My point is that they are not the Observer pattern, completely, although they get used in that manner. I was trying to point out a better way (a implementation that was only the Observer pattern).

Although I don&#039;t expect classes to police for incorrect use, it would be nice if they didn&#039;t encourage it.

@Anonymous: I never said anyone was incompetent, nor was that my intent. My argument was simply: &quot;there&#039;s a better way to do this.&quot;

I&#039;m sorry that you dislike my writing style. I fully confess that I am an engineer and not a professional writer. I&#039;m sorry that the fact that I identified things as &quot;good&quot; or &quot;bad&quot; annoyed you, but that is the way of the world. Some things really are &quot;good&quot; while others are &quot;bad.&quot;

As you might have noted, this is my personal blog, and the implicit implication is that everything here is my personal opinion. You are free to accept or reject my opinions at your whim, and it will not offend me in the least.

@igerard: Sorry to chase a rabbit here, but I&#039;d like to have a minute with your initial comment: &quot;Programming is not religious.&quot;

People say this, and mean it, but can never do it. Programming is religious, and each person has their own little cult. Whether it is over whether programming is an art or science, or if inlining is really worth it, or if source control should be used, or the indention style that should be used. Each programmer has their own idiosyncrasies that they cling to, despite the lack of evidence, or even evidence to the contrary, that they are true.

Alright, rabbit chased.

Although NSNotificationCenter can be used to implement a one-to-many relationship, it is often not used that way (at least in the code I&#039;ve seen), and it does not enforce this. Also, the syntax of its use (like I mentioned in the post) does not lend itself to the relationship of the objects.

@Brent: Thanks for pointing to the docs, but I already knew that (and mentioned it briefly in my post), and I believe you missed my point. As I stated in the post, although NSNotificationCenter will allow you to establish a one-to-many relationship, it allows many-to-many, and the common use appears to be many-to-many, even when the real relationship is one-to-many.

I will fully admit that I don&#039;t know what the original designers intended. However, I would like to point out that sword cuts both ways: unless you have information that you didn&#039;t mention, neither do you.

I also don&#039;t think the original designers intended a pure Observer pattern. My point was that although it is not an Observer pattern, it is used in that function, and Apple has not provided an appropriate one-to-many Observer pattern in Cocoa (unless KVO is it).

As far as globals goes, you took my one comment and blew it _way_ out of proportion. I admit that was probably at least partially my fault because of my attempt at humor (note the &quot;trademark&quot; sign in my statement). I never said that all globals were bad, and should never be used. I, occasionally, will use singletons and local static variables. I even clarified this in one of my earlier comments. However, my point was, in a one-to-many Observer relationship, there is no need to have a global.

To your comment that singletons aren&#039;t globals, I will have to disagree. You are correct that they will often encapsulate their member data, which makes them better that a global C struct. However, singletons share the same global access from any part of the code that proper globals do. This means they are open for being used from anywhere, which can produce much tighter coupling than necessary.</description>
		<content:encoded><![CDATA[<p>@patrick: Thanks for the info about KVO. I&#8217;d love to take it for a spin as soon as I have a project that allows me to do that.</p>
<p>Also, I don&#8217;t think bloggers were too rough on the Cocoa features. Brent and others pointed out some gotchas and limitations of the technologies, but I don&#8217;t think any of them meant: &#8220;these are bad technologies.&#8221; In fact, I remember some praise of bindings, and rightfully so.</p>
<p>@Stephane: The pattern you describe with the anchorman and the news is the Moderator pattern, not the Observer pattern. If that&#8217;s your model, then (I think) you would be correct to use NSNotificationCenter. In the Observer pattern, the observer actually cares about one specific subject (the person actually making the news in your example, as opposed to the anchorperson). My point was, in that model, NSNotificationCenter is not appropriate. Also note that the news example is a many-to-many relationship. Many people are making the news, and many people are listening to it.</p>
<p>@Nathan: I will admit I can be a bit dogmatic about design patterns, and anal about coding standards. You are correct that the notifications are their own design pattern. My point is that they are not the Observer pattern, completely, although they get used in that manner. I was trying to point out a better way (a implementation that was only the Observer pattern).</p>
<p>Although I don&#8217;t expect classes to police for incorrect use, it would be nice if they didn&#8217;t encourage it.</p>
<p>@Anonymous: I never said anyone was incompetent, nor was that my intent. My argument was simply: &#8220;there&#8217;s a better way to do this.&#8221;</p>
<p>I&#8217;m sorry that you dislike my writing style. I fully confess that I am an engineer and not a professional writer. I&#8217;m sorry that the fact that I identified things as &#8220;good&#8221; or &#8220;bad&#8221; annoyed you, but that is the way of the world. Some things really are &#8220;good&#8221; while others are &#8220;bad.&#8221;</p>
<p>As you might have noted, this is my personal blog, and the implicit implication is that everything here is my personal opinion. You are free to accept or reject my opinions at your whim, and it will not offend me in the least.</p>
<p>@igerard: Sorry to chase a rabbit here, but I&#8217;d like to have a minute with your initial comment: &#8220;Programming is not religious.&#8221;</p>
<p>People say this, and mean it, but can never do it. Programming is religious, and each person has their own little cult. Whether it is over whether programming is an art or science, or if inlining is really worth it, or if source control should be used, or the indention style that should be used. Each programmer has their own idiosyncrasies that they cling to, despite the lack of evidence, or even evidence to the contrary, that they are true.</p>
<p>Alright, rabbit chased.</p>
<p>Although NSNotificationCenter can be used to implement a one-to-many relationship, it is often not used that way (at least in the code I&#8217;ve seen), and it does not enforce this. Also, the syntax of its use (like I mentioned in the post) does not lend itself to the relationship of the objects.</p>
<p>@Brent: Thanks for pointing to the docs, but I already knew that (and mentioned it briefly in my post), and I believe you missed my point. As I stated in the post, although NSNotificationCenter will allow you to establish a one-to-many relationship, it allows many-to-many, and the common use appears to be many-to-many, even when the real relationship is one-to-many.</p>
<p>I will fully admit that I don&#8217;t know what the original designers intended. However, I would like to point out that sword cuts both ways: unless you have information that you didn&#8217;t mention, neither do you.</p>
<p>I also don&#8217;t think the original designers intended a pure Observer pattern. My point was that although it is not an Observer pattern, it is used in that function, and Apple has not provided an appropriate one-to-many Observer pattern in Cocoa (unless KVO is it).</p>
<p>As far as globals goes, you took my one comment and blew it _way_ out of proportion. I admit that was probably at least partially my fault because of my attempt at humor (note the &#8220;trademark&#8221; sign in my statement). I never said that all globals were bad, and should never be used. I, occasionally, will use singletons and local static variables. I even clarified this in one of my earlier comments. However, my point was, in a one-to-many Observer relationship, there is no need to have a global.</p>
<p>To your comment that singletons aren&#8217;t globals, I will have to disagree. You are correct that they will often encapsulate their member data, which makes them better that a global C struct. However, singletons share the same global access from any part of the code that proper globals do. This means they are open for being used from anywhere, which can produce much tighter coupling than necessary.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brent</title>
		<link>http://losingfight.com/blog/2007/04/26/in-defense-of-observers/comment-page-1/#comment-410</link>
		<dc:creator>Brent</dc:creator>
		<pubDate>Tue, 01 May 2007 02:32:57 +0000</pubDate>
		<guid isPermaLink="false">http://www.losingfight.com/blog/2007/04/26/in-defense-of-observers/#comment-410</guid>
		<description>About global variables: they are not universally bad. All C functions (like main() or NSSelectorFromString()) are in the global namespace. NSApp is in the global namespace. All classes are in the global namespace. Singletons are not bad; certainly not because they are global, though in Cocoa they usually aren&#039;t: the sharedNotificationCenter, anymore than the sharedDocumentController, is *NOT* a global; you have to ask for it from the class object.

Globally available symbols are essential for software to work properly; the alternative to global visibility would be long chains of references, which would lead to the same thing. Every object graph has a root; relative to every other object in the graph, that object is &quot;global&quot;. And sometimes, you have to talk to the root object.

Open up XCode&#039;s debugger and click on the globals disclosure triangle and check out the tremendously large number of global variables, without which, a lot of code would be much more obfuscated and difficult to use.

The problem with global variables goes back to C structures being shared around by everybody. Code all over an application could alter their contents, creating unmanageable complexity. Encapsulation solved that problem; globally available objects are not the same thing as global variables.</description>
		<content:encoded><![CDATA[<p>About global variables: they are not universally bad. All C functions (like main() or NSSelectorFromString()) are in the global namespace. NSApp is in the global namespace. All classes are in the global namespace. Singletons are not bad; certainly not because they are global, though in Cocoa they usually aren&#8217;t: the sharedNotificationCenter, anymore than the sharedDocumentController, is *NOT* a global; you have to ask for it from the class object.</p>
<p>Globally available symbols are essential for software to work properly; the alternative to global visibility would be long chains of references, which would lead to the same thing. Every object graph has a root; relative to every other object in the graph, that object is &#8220;global&#8221;. And sometimes, you have to talk to the root object.</p>
<p>Open up XCode&#8217;s debugger and click on the globals disclosure triangle and check out the tremendously large number of global variables, without which, a lot of code would be much more obfuscated and difficult to use.</p>
<p>The problem with global variables goes back to C structures being shared around by everybody. Code all over an application could alter their contents, creating unmanageable complexity. Encapsulation solved that problem; globally available objects are not the same thing as global variables.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brent</title>
		<link>http://losingfight.com/blog/2007/04/26/in-defense-of-observers/comment-page-1/#comment-409</link>
		<dc:creator>Brent</dc:creator>
		<pubDate>Tue, 01 May 2007 02:23:04 +0000</pubDate>
		<guid isPermaLink="false">http://www.losingfight.com/blog/2007/04/26/in-defense-of-observers/#comment-409</guid>
		<description>Andy,

Sorry to be blatantly contradictory, but you are free to use NSNotificationCenter (either the default, or one of your own creation) in a one-to-many manner if you desire. you simply provide the object which you are observing. Optionally, you can omit the notification name and receive all notifications regarding the observed object. From the docs:

notificationName
The name of the notification for which to register the observer; that is, only notifications with this name are delivered to the observer. When nil, the notification center doesn’t use a notification’s name to decide whether to deliver it to the observer.

notificationSender
The object whose notifications the observer wants to receive; that is, only notifications sent by this sender are delivered to the observer. When nil, the notification center doesn’t use a notification’s sender to decide whether to deliver it to the observer.

--

In any case, regardless of the actual facts, but based on the ones you present, your argument in and of itself is, as pointed out by others, fundamentally flawed. You are trying to say that the designers of Foundation (and it wasn&#039;t Apple, but NeXT) intended to implement a pattern and failed, whereas you have no way of knowing what they intended. You are merely assuming.</description>
		<content:encoded><![CDATA[<p>Andy,</p>
<p>Sorry to be blatantly contradictory, but you are free to use NSNotificationCenter (either the default, or one of your own creation) in a one-to-many manner if you desire. you simply provide the object which you are observing. Optionally, you can omit the notification name and receive all notifications regarding the observed object. From the docs:</p>
<p>notificationName<br />
The name of the notification for which to register the observer; that is, only notifications with this name are delivered to the observer. When nil, the notification center doesn’t use a notification’s name to decide whether to deliver it to the observer.</p>
<p>notificationSender<br />
The object whose notifications the observer wants to receive; that is, only notifications sent by this sender are delivered to the observer. When nil, the notification center doesn’t use a notification’s sender to decide whether to deliver it to the observer.</p>
<p>&#8211;</p>
<p>In any case, regardless of the actual facts, but based on the ones you present, your argument in and of itself is, as pointed out by others, fundamentally flawed. You are trying to say that the designers of Foundation (and it wasn&#8217;t Apple, but NeXT) intended to implement a pattern and failed, whereas you have no way of knowing what they intended. You are merely assuming.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: igerard</title>
		<link>http://losingfight.com/blog/2007/04/26/in-defense-of-observers/comment-page-1/#comment-408</link>
		<dc:creator>igerard</dc:creator>
		<pubDate>Sat, 28 Apr 2007 22:58:29 +0000</pubDate>
		<guid isPermaLink="false">http://www.losingfight.com/blog/2007/04/26/in-defense-of-observers/#comment-408</guid>
		<description>Programming is not religious.

NSNotificationCenter allow to implement observable/observer relationship/behavior in a very easy way.

If you want to implement this pattern in a one to many relationship  way it is easy with NSArray, selector, target, and category on NSObject to get code usable from everywhere in your class tree, not as clean as protocol but it does work.

You can even use NSInvocation which is an interesting object allowing more complexe signature for message targeted to the observer.

To make short, NSNotificationCenter is a compromise to get something very usable, genereic... I suspect that NSNotificationCenter use heavily Hash table, hence in some circumstance you can get poor performance, and then it is a good idea to make specialized instance of NSNotificationCenter.</description>
		<content:encoded><![CDATA[<p>Programming is not religious.</p>
<p>NSNotificationCenter allow to implement observable/observer relationship/behavior in a very easy way.</p>
<p>If you want to implement this pattern in a one to many relationship  way it is easy with NSArray, selector, target, and category on NSObject to get code usable from everywhere in your class tree, not as clean as protocol but it does work.</p>
<p>You can even use NSInvocation which is an interesting object allowing more complexe signature for message targeted to the observer.</p>
<p>To make short, NSNotificationCenter is a compromise to get something very usable, genereic&#8230; I suspect that NSNotificationCenter use heavily Hash table, hence in some circumstance you can get poor performance, and then it is a good idea to make specialized instance of NSNotificationCenter.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anoymous Coward</title>
		<link>http://losingfight.com/blog/2007/04/26/in-defense-of-observers/comment-page-1/#comment-407</link>
		<dc:creator>Anoymous Coward</dc:creator>
		<pubDate>Sat, 28 Apr 2007 13:04:35 +0000</pubDate>
		<guid isPermaLink="false">http://www.losingfight.com/blog/2007/04/26/in-defense-of-observers/#comment-407</guid>
		<description>&gt;@Anonymous: My point was people were using the
&gt; NSNotificationCenter as if it were the observer
&gt; pattern, and my point was it isn’t.

I find it curious that you&#039;re argument now involves the supposed incompetence of some nameless people. (Who are they ?) Would it not have been more honest if you had written:

&quot;I read the Design Patterns book and thought NSNotificationCenter is exactly the observer pattern, but then I noticed...&quot;


My response would be nicer, if you hadn&#039;t written in this annoying preaching style. This is &quot;good&quot; this is &quot;bad&quot;. Apple&#039;s work is &quot;shoddy&quot;. You&#039;re doing a lot of posturing and preaching, but you have very little to back it up.</description>
		<content:encoded><![CDATA[<p>&gt;@Anonymous: My point was people were using the<br />
&gt; NSNotificationCenter as if it were the observer<br />
&gt; pattern, and my point was it isn’t.</p>
<p>I find it curious that you&#8217;re argument now involves the supposed incompetence of some nameless people. (Who are they ?) Would it not have been more honest if you had written:</p>
<p>&#8220;I read the Design Patterns book and thought NSNotificationCenter is exactly the observer pattern, but then I noticed&#8230;&#8221;</p>
<p>My response would be nicer, if you hadn&#8217;t written in this annoying preaching style. This is &#8220;good&#8221; this is &#8220;bad&#8221;. Apple&#8217;s work is &#8220;shoddy&#8221;. You&#8217;re doing a lot of posturing and preaching, but you have very little to back it up.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nathan Day</title>
		<link>http://losingfight.com/blog/2007/04/26/in-defense-of-observers/comment-page-1/#comment-406</link>
		<dc:creator>Nathan Day</dc:creator>
		<pubDate>Sat, 28 Apr 2007 01:15:42 +0000</pubDate>
		<guid isPermaLink="false">http://www.losingfight.com/blog/2007/04/26/in-defense-of-observers/#comment-406</guid>
		<description>You can get one-to-many relationship when an notification observer specifies which object it wants to receive notifications from. The great thing about Apples Notification Centre is it can function as a one-to-many and a many-to-many and individual notifications can act as both ways, letting the observer decided. You seem to be a little dogmatic about design patterns, the notifications are there own design pattern that can do the observer pattern, and you criticism seems to they don&#039;t police the observer pattern for your.</description>
		<content:encoded><![CDATA[<p>You can get one-to-many relationship when an notification observer specifies which object it wants to receive notifications from. The great thing about Apples Notification Centre is it can function as a one-to-many and a many-to-many and individual notifications can act as both ways, letting the observer decided. You seem to be a little dogmatic about design patterns, the notifications are there own design pattern that can do the observer pattern, and you criticism seems to they don&#8217;t police the observer pattern for your.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stephane</title>
		<link>http://losingfight.com/blog/2007/04/26/in-defense-of-observers/comment-page-1/#comment-405</link>
		<dc:creator>Stephane</dc:creator>
		<pubDate>Fri, 27 Apr 2007 22:49:31 +0000</pubDate>
		<guid isPermaLink="false">http://www.losingfight.com/blog/2007/04/26/in-defense-of-observers/#comment-405</guid>
		<description>I don&#039;t see the point with the one-to-many thing. The purpose of a notification is not to care about the sender but about the message. When you&#039;re watching TV news, it&#039;s not the anchorman that matters but the news itself.

For me, NS[Distributed]NotificationCenter just works.</description>
		<content:encoded><![CDATA[<p>I don&#8217;t see the point with the one-to-many thing. The purpose of a notification is not to care about the sender but about the message. When you&#8217;re watching TV news, it&#8217;s not the anchorman that matters but the news itself.</p>
<p>For me, NS[Distributed]NotificationCenter just works.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: patrick</title>
		<link>http://losingfight.com/blog/2007/04/26/in-defense-of-observers/comment-page-1/#comment-404</link>
		<dc:creator>patrick</dc:creator>
		<pubDate>Fri, 27 Apr 2007 20:15:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.losingfight.com/blog/2007/04/26/in-defense-of-observers/#comment-404</guid>
		<description>@Andy: Definitely check out KVO. The implementation (both under the hood an the API) may be a little bit strange, but that doesn&#039;t detract from the fact that it works. It&#039;s Cocoa&#039;s Observer, and I find it really useful.

The thing that surprised me in this week&#039;s &#039;large projects&#039; discussion was how a number of high profile (== blogging) developers criticized some great Cocoa features. Notifications suddenly confuse the flow of control, KVO is &#039;only for preferences&#039;, bindings are &#039;hidden in the nib&#039; and are to be avoided. Oh my... Let&#039;s all agree that these are wonderful technologies that make our lives so much easier. And let&#039;s remind ourselves that the _only_ effective way to remember how a program works is to read the _documentation you wrote when you created the code_... If you were lazy, don&#039;t take it out on the framework, it can&#039;t help it.

Which brings us to the sorry state of HeaderDoc ;-\</description>
		<content:encoded><![CDATA[<p>@Andy: Definitely check out KVO. The implementation (both under the hood an the API) may be a little bit strange, but that doesn&#8217;t detract from the fact that it works. It&#8217;s Cocoa&#8217;s Observer, and I find it really useful.</p>
<p>The thing that surprised me in this week&#8217;s &#8216;large projects&#8217; discussion was how a number of high profile (== blogging) developers criticized some great Cocoa features. Notifications suddenly confuse the flow of control, KVO is &#8216;only for preferences&#8217;, bindings are &#8216;hidden in the nib&#8217; and are to be avoided. Oh my&#8230; Let&#8217;s all agree that these are wonderful technologies that make our lives so much easier. And let&#8217;s remind ourselves that the _only_ effective way to remember how a program works is to read the _documentation you wrote when you created the code_&#8230; If you were lazy, don&#8217;t take it out on the framework, it can&#8217;t help it.</p>
<p>Which brings us to the sorry state of HeaderDoc ;-\</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andy</title>
		<link>http://losingfight.com/blog/2007/04/26/in-defense-of-observers/comment-page-1/#comment-403</link>
		<dc:creator>Andy</dc:creator>
		<pubDate>Fri, 27 Apr 2007 18:26:57 +0000</pubDate>
		<guid isPermaLink="false">http://www.losingfight.com/blog/2007/04/26/in-defense-of-observers/#comment-403</guid>
		<description>@Jamie: &lt;em&gt;Would be nice if there was some more felxible manner to implement this.&lt;/em&gt;

I thought I outlined a nice way to implement it at the end of the post. :-) You simply aggregate the Observer or Subject object, which contains a pointer back to the real observer or subject. In Objective-C the Observer (or Subject) can simply forward the message invocations to the real object. There is a level indirection there, but its still quite usable. In fact I&#039;ve seen this design used in C++ where there is multiple inheritance.

@Diederik: Unfortunately, I haven&#039;t really used KVO, so I can&#039;t really comment on them. I know some others have expressed displeasure with how they&#039;re implemented.

@Patrick: Agreed, NSNotificationCenter doesn&#039;t implement the observer pattern, that was my point. However, people (including from Apple) are using it in that manner. I agree, the way it is architected is useful, just not as an observer pattern.

Also, I&#039;m not against singletons. I like them, and use them. As you say, there are times to use them, and times when they&#039;re not appropriate. I&#039;m saying when you want an observer pattern, they&#039;re not appropriate.

@Anonymous: My point was people were using the NSNotificationCenter as if it were the observer pattern, and my point was it isn&#039;t.

@Shawn: Yes, that is true. But I still think NSNotificationCenter shouldn&#039;t be used in place of the observer pattern, when that&#039;s appropriate. NSNotificationCenter still represents a many-to-many relationship, even when you use multiple of them.</description>
		<content:encoded><![CDATA[<p>@Jamie: <em>Would be nice if there was some more felxible manner to implement this.</em></p>
<p>I thought I outlined a nice way to implement it at the end of the post. <img src='http://losingfight.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  You simply aggregate the Observer or Subject object, which contains a pointer back to the real observer or subject. In Objective-C the Observer (or Subject) can simply forward the message invocations to the real object. There is a level indirection there, but its still quite usable. In fact I&#8217;ve seen this design used in C++ where there is multiple inheritance.</p>
<p>@Diederik: Unfortunately, I haven&#8217;t really used KVO, so I can&#8217;t really comment on them. I know some others have expressed displeasure with how they&#8217;re implemented.</p>
<p>@Patrick: Agreed, NSNotificationCenter doesn&#8217;t implement the observer pattern, that was my point. However, people (including from Apple) are using it in that manner. I agree, the way it is architected is useful, just not as an observer pattern.</p>
<p>Also, I&#8217;m not against singletons. I like them, and use them. As you say, there are times to use them, and times when they&#8217;re not appropriate. I&#8217;m saying when you want an observer pattern, they&#8217;re not appropriate.</p>
<p>@Anonymous: My point was people were using the NSNotificationCenter as if it were the observer pattern, and my point was it isn&#8217;t.</p>
<p>@Shawn: Yes, that is true. But I still think NSNotificationCenter shouldn&#8217;t be used in place of the observer pattern, when that&#8217;s appropriate. NSNotificationCenter still represents a many-to-many relationship, even when you use multiple of them.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
