<?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"
	>
<channel>
	<title>Comments on: Simplifying dependencies, increasing&#160;complexity?</title>
	<atom:link href="http://www.magpiebrain.com/blog/2004/07/20/simplifying-dependencies-increasing-complexity/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.magpiebrain.com/blog/2004/07/20/simplifying-dependencies-increasing-complexity/</link>
	<description>Sam Newman's blog</description>
	<pubDate>Sat, 05 Jul 2008 00:45:48 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
		<item>
		<title>By: Sam Newman</title>
		<link>http://www.magpiebrain.com/blog/2004/07/20/simplifying-dependencies-increasing-complexity/#comment-476</link>
		<dc:creator>Sam Newman</dc:creator>
		<pubDate>Fri, 23 Jul 2004 10:28:51 +0000</pubDate>
		<guid isPermaLink="false">http://www.magpiebrain.com/2004/07/20/simplifying-dependencies-increasing-complexity/#comment-476</guid>
		<description>I've often thought the same thing myself. Attributes coming in 1.5 might provide some of this - I guess we'll have to wait and see how it's handled. Off the top of my head I can't think of any language which has support specifically for event firing/listening - some languages make it easy by their very nature of course. Speaking personally I'd rather code an event/listener pattern in Java than in C or Pascal :-)
</description>
		<content:encoded><![CDATA[<p>I&#8217;ve often thought the same thing myself. Attributes coming in 1.5 might provide some of this &#8211; I guess we&#8217;ll have to wait and see how it&#8217;s handled. Off the top of my head I can&#8217;t think of any language which has support specifically for event firing/listening &#8211; some languages make it easy by their very nature of course. Speaking personally I&#8217;d rather code an event/listener pattern in Java than in C or Pascal :-)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Glen Stampoultzis</title>
		<link>http://www.magpiebrain.com/blog/2004/07/20/simplifying-dependencies-increasing-complexity/#comment-475</link>
		<dc:creator>Glen Stampoultzis</dc:creator>
		<pubDate>Fri, 23 Jul 2004 10:20:28 +0000</pubDate>
		<guid isPermaLink="false">http://www.magpiebrain.com/2004/07/20/simplifying-dependencies-increasing-complexity/#comment-475</guid>
		<description>I must say I really like this subscribe to comments feature.  

I'm aware of the support classes.  It's still a lot of buggering around for what really should be a simple  thing.  Perhaps what we really need here is better language support for this idiom.  Not sure what form that would take however.</description>
		<content:encoded><![CDATA[<p>I must say I really like this subscribe to comments feature.  </p>
<p>I&#8217;m aware of the support classes.  It&#8217;s still a lot of buggering around for what really should be a simple  thing.  Perhaps what we really need here is better language support for this idiom.  Not sure what form that would take however.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sam Newman</title>
		<link>http://www.magpiebrain.com/blog/2004/07/20/simplifying-dependencies-increasing-complexity/#comment-474</link>
		<dc:creator>Sam Newman</dc:creator>
		<pubDate>Fri, 23 Jul 2004 09:59:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.magpiebrain.com/2004/07/20/simplifying-dependencies-increasing-complexity/#comment-474</guid>
		<description>There are also some support classes, such as "EventListenerList":http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/event/EventListenerList.html and "PropertyChangeSupport":http://java.sun.com/j2se/1.4.2/docs/api/java/beans/PropertyChangeSupport.html which can make this process easier. I agree with Doug - this is one place where multiple inheritance would be nice. I typically end up creating Abstract implementations to handle event firing, or else use support classes. Another approach would be to use CGLIB proxies to create listenable implementations, although the amount of upfront coding, performance implications of using proxies and potential for confusion are rarely worth it.</description>
		<content:encoded><![CDATA[<p>There are also some support classes, such as <a href="http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/event/EventListenerList.html" onclick="javascript:pageTracker._trackPageview('/outbound/comment/java.sun.com');">EventListenerList</a> and <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/beans/PropertyChangeSupport.html" onclick="javascript:pageTracker._trackPageview('/outbound/comment/java.sun.com');">PropertyChangeSupport</a> which can make this process easier. I agree with Doug &#8211; this is one place where multiple inheritance would be nice. I typically end up creating Abstract implementations to handle event firing, or else use support classes. Another approach would be to use CGLIB proxies to create listenable implementations, although the amount of upfront coding, performance implications of using proxies and potential for confusion are rarely worth it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Doug</title>
		<link>http://www.magpiebrain.com/blog/2004/07/20/simplifying-dependencies-increasing-complexity/#comment-473</link>
		<dc:creator>Doug</dc:creator>
		<pubDate>Thu, 22 Jul 2004 16:26:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.magpiebrain.com/2004/07/20/simplifying-dependencies-increasing-complexity/#comment-473</guid>
		<description>bq. the infrastructure required to deal with adding and removing listeners, firing off events, creating interfaces put me off

Java does provide the java.util.Observable class and java.util.Observer interface. Too bad Java doesn't believe in multiple inheritance, though. Or at least, if Observable had implemented an interface that your class could implement by delegation.

Of course, if you have multiple events that might want to be observed independently, then you _need_ multiple Observable objects and inheritance wouldn't do the job anyway. Then the simplest approach is for the observer to request the appropriate Observable from your object, and register itself with the Observable. A nicer approach is for you to create event-specific add/delete methods in your object that simply delegate to the appropriate Observables.</description>
		<content:encoded><![CDATA[<blockquote>
<p>the infrastructure required to deal with adding and removing listeners, firing off events, creating interfaces put me off</p>
</blockquote>
<p>Java does provide the java.util.Observable class and java.util.Observer interface. Too bad Java doesn&#8217;t believe in multiple inheritance, though. Or at least, if Observable had implemented an interface that your class could implement by delegation.</p>
<p>Of course, if you have multiple events that might want to be observed independently, then you <em>need</em> multiple Observable objects and inheritance wouldn&#8217;t do the job anyway. Then the simplest approach is for the observer to request the appropriate Observable from your object, and register itself with the Observable. A nicer approach is for you to create event-specific add/delete methods in your object that simply delegate to the appropriate Observables.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Glen Stampoultzis</title>
		<link>http://www.magpiebrain.com/blog/2004/07/20/simplifying-dependencies-increasing-complexity/#comment-472</link>
		<dc:creator>Glen Stampoultzis</dc:creator>
		<pubDate>Thu, 22 Jul 2004 04:53:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.magpiebrain.com/2004/07/20/simplifying-dependencies-increasing-complexity/#comment-472</guid>
		<description>Really interesting discussion.  Often I've wanted to use listeners but frequently the infrastructure required to deal with adding and removing listeners, firing off events, creating interfaces put me off.  I wish adding listeners didn't require so much code.

Doug brings up some pretty good points too.</description>
		<content:encoded><![CDATA[<p>Really interesting discussion.  Often I&#8217;ve wanted to use listeners but frequently the infrastructure required to deal with adding and removing listeners, firing off events, creating interfaces put me off.  I wish adding listeners didn&#8217;t require so much code.</p>
<p>Doug brings up some pretty good points too.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sam Newman</title>
		<link>http://www.magpiebrain.com/blog/2004/07/20/simplifying-dependencies-increasing-complexity/#comment-471</link>
		<dc:creator>Sam Newman</dc:creator>
		<pubDate>Wed, 21 Jul 2004 13:51:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.magpiebrain.com/2004/07/20/simplifying-dependencies-increasing-complexity/#comment-471</guid>
		<description>Darren wrote:

bq. An object’s instantiator may not be the thing that uses it, and passing dependencies into a constructor isn’t really adding complexity, just making the complexity that is already present in the system more explicit.

But the use of some tecnniques to instantiate the object (I'm thinking Spring and Pico here) can often obsure how the dependencies are being created and passed in in the first place. I'm not saying that this is a reason _not_ to use Spring or Pico, but that when using them in a system (especially an existing system) you can end up muddying the water somewhat.</description>
		<content:encoded><![CDATA[<p>Darren wrote:</p>
<blockquote>
<p>An object’s instantiator may not be the thing that uses it, and passing dependencies into a constructor isn’t really adding complexity, just making the complexity that is already present in the system more explicit.</p>
</blockquote>
<p>But the use of some tecnniques to instantiate the object (I&#8217;m thinking Spring and Pico here) can often obsure how the dependencies are being created and passed in in the first place. I&#8217;m not saying that this is a reason <em>not</em> to use Spring or Pico, but that when using them in a system (especially an existing system) you can end up muddying the water somewhat.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Darren</title>
		<link>http://www.magpiebrain.com/blog/2004/07/20/simplifying-dependencies-increasing-complexity/#comment-470</link>
		<dc:creator>Darren</dc:creator>
		<pubDate>Wed, 21 Jul 2004 12:00:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.magpiebrain.com/2004/07/20/simplifying-dependencies-increasing-complexity/#comment-470</guid>
		<description>What if both the Viewer and the Listener implemented the same interface and you passed that in instead?  Wouldn't the code for both examples then be exactly the same?  The list of listeners could also be imagined as a CompositeViewer, which would take the responsibility of iterating over the list of listeners out of the View.

I tend to think of 'construction time' and 'use time' of an object as distinct and separate.  An object's instantiator may not be the thing that uses it, and passing dependencies into a constructor isn't really adding complexity, just making the complexity that is already present in the system more explicit.</description>
		<content:encoded><![CDATA[<p>What if both the Viewer and the Listener implemented the same interface and you passed that in instead?  Wouldn&#8217;t the code for both examples then be exactly the same?  The list of listeners could also be imagined as a CompositeViewer, which would take the responsibility of iterating over the list of listeners out of the View.</p>
<p>I tend to think of &#8216;construction time&#8217; and &#8216;use time&#8217; of an object as distinct and separate.  An object&#8217;s instantiator may not be the thing that uses it, and passing dependencies into a constructor isn&#8217;t really adding complexity, just making the complexity that is already present in the system more explicit.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kristopher Schmidt</title>
		<link>http://www.magpiebrain.com/blog/2004/07/20/simplifying-dependencies-increasing-complexity/#comment-469</link>
		<dc:creator>Kristopher Schmidt</dc:creator>
		<pubDate>Tue, 20 Jul 2004 18:20:21 +0000</pubDate>
		<guid isPermaLink="false">http://www.magpiebrain.com/2004/07/20/simplifying-dependencies-increasing-complexity/#comment-469</guid>
		<description>You have simply changed your dependency from a Viewer to a listener list.  Dependency injection can be used to set up either the Viewer or the listener list dependency, so this design decision has nothing to do with dependency injection but rather with tighter vs looser coupling.</description>
		<content:encoded><![CDATA[<p>You have simply changed your dependency from a Viewer to a listener list.  Dependency injection can be used to set up either the Viewer or the listener list dependency, so this design decision has nothing to do with dependency injection but rather with tighter vs looser coupling.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Doug</title>
		<link>http://www.magpiebrain.com/blog/2004/07/20/simplifying-dependencies-increasing-complexity/#comment-468</link>
		<dc:creator>Doug</dc:creator>
		<pubDate>Tue, 20 Jul 2004 18:00:58 +0000</pubDate>
		<guid isPermaLink="false">http://www.magpiebrain.com/2004/07/20/simplifying-dependencies-increasing-complexity/#comment-468</guid>
		<description>That's supposed to be "C Plus Plus" in the penultimate paragraph. Apparently plus signs do something weird, too :-)</description>
		<content:encoded><![CDATA[<p>That&#8217;s supposed to be &#8220;C Plus Plus&#8221; in the penultimate paragraph. Apparently plus signs do something weird, too :-)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Doug</title>
		<link>http://www.magpiebrain.com/blog/2004/07/20/simplifying-dependencies-increasing-complexity/#comment-467</link>
		<dc:creator>Doug</dc:creator>
		<pubDate>Tue, 20 Jul 2004 17:57:56 +0000</pubDate>
		<guid isPermaLink="false">http://www.magpiebrain.com/2004/07/20/simplifying-dependencies-increasing-complexity/#comment-467</guid>
		<description>It's not about "how the error will be displayed." It's about "what ELSE will happen?"

An example from (painful) personal experience: an object was iterating through a list and found something it didn't like. It notified its listeners, one of whom tracked down the offending list item and removed it from the list. After the listeners returned, the original object attempted to continue using the iterator, with unpleasant results. (In Java it would be a ConcurrentModificationException).

This is where the danger is: the listener interface being used had no contracts which said what the listener was (and more importantly, wasn't) allowed to do. The listener went off doing something that seemed to be perfectly reasonable and quite helpful: eliminating the trouble-making situation. However, the original object was in a state which could not tolerate that particular kind of help.

Not a problem in Java, but I've seen an extreme example in C  : one of the listeners made a "fixup" that indirectly resulted in the original object being deleted. When the listeners returned, hilarity ensued.

Certainly the Observer pattern CAN be used without problems; people have been doing so for an awful long time. But there are hazards that must be considered, and having no contracts on the Listener and then using a Controller as a Listener definitely increases the "threat level."</description>
		<content:encoded><![CDATA[<p>It&#8217;s not about &#8220;how the error will be displayed.&#8221; It&#8217;s about &#8220;what ELSE will happen?&#8221;</p>
<p>An example from (painful) personal experience: an object was iterating through a list and found something it didn&#8217;t like. It notified its listeners, one of whom tracked down the offending list item and removed it from the list. After the listeners returned, the original object attempted to continue using the iterator, with unpleasant results. (In Java it would be a ConcurrentModificationException).</p>
<p>This is where the danger is: the listener interface being used had no contracts which said what the listener was (and more importantly, wasn&#8217;t) allowed to do. The listener went off doing something that seemed to be perfectly reasonable and quite helpful: eliminating the trouble-making situation. However, the original object was in a state which could not tolerate that particular kind of help.</p>
<p>Not a problem in Java, but I&#8217;ve seen an extreme example in C  : one of the listeners made a &#8220;fixup&#8221; that indirectly resulted in the original object being deleted. When the listeners returned, hilarity ensued.</p>
<p>Certainly the Observer pattern CAN be used without problems; people have been doing so for an awful long time. But there are hazards that must be considered, and having no contracts on the Listener and then using a Controller as a Listener definitely increases the &#8220;threat level.&#8221; </p>
]]></content:encoded>
	</item>
</channel>
</rss>
