<?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: Do not start with an Interface</title>
	<atom:link href="http://www.indiangeek.net/2006/10/25/do-not-start-with-an-interface/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.indiangeek.net/2006/10/25/do-not-start-with-an-interface/</link>
	<description>Perspectives on Computer Science and Software Engineering</description>
	<lastBuildDate>Mon, 08 Mar 2010 18:54:53 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Tim Yen</title>
		<link>http://www.indiangeek.net/2006/10/25/do-not-start-with-an-interface/comment-page-1/#comment-2336</link>
		<dc:creator>Tim Yen</dc:creator>
		<pubDate>Wed, 08 Oct 2008 11:37:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.indiangeek.net/?p=41#comment-2336</guid>
		<description>My experience has lead me away from inheritance. Largely because I have ended up with large unwieldy inheritance structures that needed to be modified and morphed.  It sounds like you have ended up with the same situation but using interfaces.  Maybe it is just a function of the sheer complexity of the programs we code?

Inheritance always seemed easy in the OO books but in practice it can be a real pain.  The same code using interfaces may also be just as much a pain in the long run.  I have yet to run into any large unwieldy interface structures, but the more I use them the more I can see it happening.</description>
		<content:encoded><![CDATA[<p>My experience has lead me away from inheritance. Largely because I have ended up with large unwieldy inheritance structures that needed to be modified and morphed.  It sounds like you have ended up with the same situation but using interfaces.  Maybe it is just a function of the sheer complexity of the programs we code?</p>
<p>Inheritance always seemed easy in the OO books but in practice it can be a real pain.  The same code using interfaces may also be just as much a pain in the long run.  I have yet to run into any large unwieldy interface structures, but the more I use them the more I can see it happening.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ricky Clarkson</title>
		<link>http://www.indiangeek.net/2006/10/25/do-not-start-with-an-interface/comment-page-1/#comment-2322</link>
		<dc:creator>Ricky Clarkson</dc:creator>
		<pubDate>Thu, 28 Aug 2008 23:39:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.indiangeek.net/?p=41#comment-2322</guid>
		<description>Programming to an interface need not allow your users to freely interchange interface and implementation types, if you hide the implementation type behind a factory method (potentially as an anonymous class).

An interface can be annoying when you feel the urge to add static methods - sometimes I use abstract classes only for this reason.

There may be parts of the contract that you cannot specify or check well enough in an interface that makes you rather use a concrete class.  For example, the algebraic type Option with implementations Some and None - it is useful to be able to guarantee that Some and None are the only implementations.</description>
		<content:encoded><![CDATA[<p>Programming to an interface need not allow your users to freely interchange interface and implementation types, if you hide the implementation type behind a factory method (potentially as an anonymous class).</p>
<p>An interface can be annoying when you feel the urge to add static methods &#8211; sometimes I use abstract classes only for this reason.</p>
<p>There may be parts of the contract that you cannot specify or check well enough in an interface that makes you rather use a concrete class.  For example, the algebraic type Option with implementations Some and None &#8211; it is useful to be able to guarantee that Some and None are the only implementations.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Larry Singer</title>
		<link>http://www.indiangeek.net/2006/10/25/do-not-start-with-an-interface/comment-page-1/#comment-2321</link>
		<dc:creator>Larry Singer</dc:creator>
		<pubDate>Wed, 27 Aug 2008 06:28:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.indiangeek.net/?p=41#comment-2321</guid>
		<description>I totally agree that interfaces are not usually required.

The mantra &quot;code to the interface&quot; is so often misunderstood that it is dangerous. It is badly in need of being publicly branded as an anti-pattern.

An example of this misunderstanding is ak&#039;s comment above about requiring interfaces for mocking. Most Java mock object libraries support mocking of classes as well as interfaces (though you may need to enable this explicitly). This is due to the magic of libraries such as CGLIB.</description>
		<content:encoded><![CDATA[<p>I totally agree that interfaces are not usually required.</p>
<p>The mantra &#8220;code to the interface&#8221; is so often misunderstood that it is dangerous. It is badly in need of being publicly branded as an anti-pattern.</p>
<p>An example of this misunderstanding is ak&#8217;s comment above about requiring interfaces for mocking. Most Java mock object libraries support mocking of classes as well as interfaces (though you may need to enable this explicitly). This is due to the magic of libraries such as CGLIB.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chuck</title>
		<link>http://www.indiangeek.net/2006/10/25/do-not-start-with-an-interface/comment-page-1/#comment-2320</link>
		<dc:creator>Chuck</dc:creator>
		<pubDate>Tue, 26 Aug 2008 21:26:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.indiangeek.net/?p=41#comment-2320</guid>
		<description>Use interfaces for the classes in your API where the implementation is likely to change or be extended or that may need to be proxied. Using an interface makes it possible to compose multiple implementation classes in a single class that implements those interfaces. Java proxies require an interface so if you think that a user may want to proxy your class then create an interface for it.

If it is likely that only one implementation of a class is needed then skip the interface and create the class or maybe an abstract base class. When to create interfaces depends on how the API is going to be used and how long it is going to be in service and the likelihood that it will have multiple and concurrent implementations.

For more info on creating useable API&#039;s I recommend a talk given by Josh Bloch at Google. Search for &quot;How To Design A Good API and Why it Matters&quot;.</description>
		<content:encoded><![CDATA[<p>Use interfaces for the classes in your API where the implementation is likely to change or be extended or that may need to be proxied. Using an interface makes it possible to compose multiple implementation classes in a single class that implements those interfaces. Java proxies require an interface so if you think that a user may want to proxy your class then create an interface for it.</p>
<p>If it is likely that only one implementation of a class is needed then skip the interface and create the class or maybe an abstract base class. When to create interfaces depends on how the API is going to be used and how long it is going to be in service and the likelihood that it will have multiple and concurrent implementations.</p>
<p>For more info on creating useable API&#8217;s I recommend a talk given by Josh Bloch at Google. Search for &#8220;How To Design A Good API and Why it Matters&#8221;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris Wash</title>
		<link>http://www.indiangeek.net/2006/10/25/do-not-start-with-an-interface/comment-page-1/#comment-2319</link>
		<dc:creator>Chris Wash</dc:creator>
		<pubDate>Tue, 26 Aug 2008 18:58:29 +0000</pubDate>
		<guid isPermaLink="false">http://www.indiangeek.net/?p=41#comment-2319</guid>
		<description>Also +1 to landlord - hiding details behind an interface allows you to fake that interaction out (using a mock or having a fake/stub stand in for the real component) which makes testing much easier.</description>
		<content:encoded><![CDATA[<p>Also +1 to landlord &#8211; hiding details behind an interface allows you to fake that interaction out (using a mock or having a fake/stub stand in for the real component) which makes testing much easier.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris Wash</title>
		<link>http://www.indiangeek.net/2006/10/25/do-not-start-with-an-interface/comment-page-1/#comment-2318</link>
		<dc:creator>Chris Wash</dc:creator>
		<pubDate>Tue, 26 Aug 2008 18:52:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.indiangeek.net/?p=41#comment-2318</guid>
		<description>+1 to Mark Smith&#039;s comment.

Another overloaded term causing confusion.

It&#039;s a good idea to have &quot;Program to an interface, not an implementation&quot; in the back of your head, but, as you state, that does not directly translate into creating an interface between every component of your system.  When you talk about making changes in two places, your initial design was in violation of the open-closed principle.  I think of the explicit interface of C++ or Java as an API.

It&#039;s all about managing dependencies between your code by thinking about polymorphism.
The idea is that the interaction of your classes should be defined by an implicit interface, and when you are designing, you&#039;re fitting those pieces together.  When you go to code, it is then that you actually wire up, solder, plug in those interactions.

Here&#039;s what Erich Gamma (one of the GoF authors) says about it in an interview:

Program to an interface, not an implementation

Bill Venners: In the introduction of the GoF book, you mention two principles of reusable object-oriented design. The first principle is: &quot;Program to an interface, not an implementation.&quot; What&#039;s that really mean, and why do it?

Erich Gamma: This principle is really about dependency relationships which have to be carefully managed in a large app. It&#039;s easy to add a dependency on a class. It&#039;s almost too easy; just add an import statement and modern Java development tools like Eclipse even write this statement for you. Interestingly the inverse isn&#039;t that easy and getting rid of an unwanted dependency can be real refactoring work or even worse, block you from reusing the code in another context. For this reason you have to develop with open eyes when it comes to introducing dependencies. This principle tells us that depending on an interface is often beneficial. 

You can find the rest of the interview here: http://www.artima.com/lejava/articles/designprinciples.html</description>
		<content:encoded><![CDATA[<p>+1 to Mark Smith&#8217;s comment.</p>
<p>Another overloaded term causing confusion.</p>
<p>It&#8217;s a good idea to have &#8220;Program to an interface, not an implementation&#8221; in the back of your head, but, as you state, that does not directly translate into creating an interface between every component of your system.  When you talk about making changes in two places, your initial design was in violation of the open-closed principle.  I think of the explicit interface of C++ or Java as an API.</p>
<p>It&#8217;s all about managing dependencies between your code by thinking about polymorphism.<br />
The idea is that the interaction of your classes should be defined by an implicit interface, and when you are designing, you&#8217;re fitting those pieces together.  When you go to code, it is then that you actually wire up, solder, plug in those interactions.</p>
<p>Here&#8217;s what Erich Gamma (one of the GoF authors) says about it in an interview:</p>
<p>Program to an interface, not an implementation</p>
<p>Bill Venners: In the introduction of the GoF book, you mention two principles of reusable object-oriented design. The first principle is: &#8220;Program to an interface, not an implementation.&#8221; What&#8217;s that really mean, and why do it?</p>
<p>Erich Gamma: This principle is really about dependency relationships which have to be carefully managed in a large app. It&#8217;s easy to add a dependency on a class. It&#8217;s almost too easy; just add an import statement and modern Java development tools like Eclipse even write this statement for you. Interestingly the inverse isn&#8217;t that easy and getting rid of an unwanted dependency can be real refactoring work or even worse, block you from reusing the code in another context. For this reason you have to develop with open eyes when it comes to introducing dependencies. This principle tells us that depending on an interface is often beneficial. </p>
<p>You can find the rest of the interview here: <a href="http://www.artima.com/lejava/articles/designprinciples.html" rel="nofollow">http://www.artima.com/lejava/articles/designprinciples.html</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steven</title>
		<link>http://www.indiangeek.net/2006/10/25/do-not-start-with-an-interface/comment-page-1/#comment-2317</link>
		<dc:creator>Steven</dc:creator>
		<pubDate>Tue, 26 Aug 2008 06:31:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.indiangeek.net/?p=41#comment-2317</guid>
		<description>I find programming to an interface works quite well.

However, if you find that your class is evolving beyond the original purpose, then it&#039;s time to create a new class and/or interface (extending your previous if desired).</description>
		<content:encoded><![CDATA[<p>I find programming to an interface works quite well.</p>
<p>However, if you find that your class is evolving beyond the original purpose, then it&#8217;s time to create a new class and/or interface (extending your previous if desired).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: landlord</title>
		<link>http://www.indiangeek.net/2006/10/25/do-not-start-with-an-interface/comment-page-1/#comment-2316</link>
		<dc:creator>landlord</dc:creator>
		<pubDate>Mon, 25 Aug 2008 19:31:28 +0000</pubDate>
		<guid isPermaLink="false">http://www.indiangeek.net/?p=41#comment-2316</guid>
		<description>Your experience with interfaces will vary depending on your mileage and problem solving approach.  I have had good success with interfaces and generally start with interface design as opposed to concrete classes.  Code integration is one of a group of parameters you need to consider in your adoption of interfaces.  It is certainly NOT the only one.

I have found interfaces to be and advantage while mocking unit test cases.  Also while working with inversion of control (I use castle), interfaces provide a great deal of flexibility event when the code is internal and not expected to have multiple implementations.

Refactoring tools included or added to you favorite tool allow the addition/modification of methods and properties to be relatively painless.  The little extra effort pays up the flexibilities in unit testing, IOC and preliminary design.</description>
		<content:encoded><![CDATA[<p>Your experience with interfaces will vary depending on your mileage and problem solving approach.  I have had good success with interfaces and generally start with interface design as opposed to concrete classes.  Code integration is one of a group of parameters you need to consider in your adoption of interfaces.  It is certainly NOT the only one.</p>
<p>I have found interfaces to be and advantage while mocking unit test cases.  Also while working with inversion of control (I use castle), interfaces provide a great deal of flexibility event when the code is internal and not expected to have multiple implementations.</p>
<p>Refactoring tools included or added to you favorite tool allow the addition/modification of methods and properties to be relatively painless.  The little extra effort pays up the flexibilities in unit testing, IOC and preliminary design.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mark Lee Smith</title>
		<link>http://www.indiangeek.net/2006/10/25/do-not-start-with-an-interface/comment-page-1/#comment-2315</link>
		<dc:creator>Mark Lee Smith</dc:creator>
		<pubDate>Mon, 25 Aug 2008 16:14:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.indiangeek.net/?p=41#comment-2315</guid>
		<description>To clarify: programming to an implicit interface is advocated, not programming to an explicit interface. Thats not to say that explicit interfaces don&#039;t have there uses :).</description>
		<content:encoded><![CDATA[<p>To clarify: programming to an implicit interface is advocated, not programming to an explicit interface. Thats not to say that explicit interfaces don&#8217;t have there uses <img src='http://www.indiangeek.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mark Lee Smith</title>
		<link>http://www.indiangeek.net/2006/10/25/do-not-start-with-an-interface/comment-page-1/#comment-2314</link>
		<dc:creator>Mark Lee Smith</dc:creator>
		<pubDate>Mon, 25 Aug 2008 16:10:51 +0000</pubDate>
		<guid isPermaLink="false">http://www.indiangeek.net/?p=41#comment-2314</guid>
		<description>The problem is that you&#039;re confusing implicit interfaces with explicit interfaces :). 


Much of the design patterns literature talks about programming to an interface. This stems from the the archetypal book on the subject: &#039;The Design Patterns Elements of Reusable Object-Oriented Software&#039;.

The authors were very careful to define the term interface, referring to the [implicit] interface of an object or number of objects. Unfortunately it&#039;s still interpreted as referring to the [explicit] interface construct as exhibited by languages like C# and Java.  


In this book was written by Smalltalk programmers and the examples appeared either in Smalltalk and or C++. Importantly, neither of these languages posses explicit interfaces.


In Smalltalk, messages are sent to objects at runtime. Given a message an object chooses how to respond; it may choose to ignore the message. Desecrate objects can respond differently to a message. The end result is that programs are written against implicit interfaces. There&#039;s no need to explicitly define the interface of your objects :).


Note: In Objective-C the interface confusion doesn&#039;t exist as explicit interfaces are called Protocols. This is a much better name for explicit interfaces. If you have the opportunity I&#039;d recommend learning this language as it embodies a lot of the ideas from Smalltalk, in a natively compiled language.</description>
		<content:encoded><![CDATA[<p>The problem is that you&#8217;re confusing implicit interfaces with explicit interfaces <img src='http://www.indiangeek.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . </p>
<p>Much of the design patterns literature talks about programming to an interface. This stems from the the archetypal book on the subject: &#8216;The Design Patterns Elements of Reusable Object-Oriented Software&#8217;.</p>
<p>The authors were very careful to define the term interface, referring to the [implicit] interface of an object or number of objects. Unfortunately it&#8217;s still interpreted as referring to the [explicit] interface construct as exhibited by languages like C# and Java.  </p>
<p>In this book was written by Smalltalk programmers and the examples appeared either in Smalltalk and or C++. Importantly, neither of these languages posses explicit interfaces.</p>
<p>In Smalltalk, messages are sent to objects at runtime. Given a message an object chooses how to respond; it may choose to ignore the message. Desecrate objects can respond differently to a message. The end result is that programs are written against implicit interfaces. There&#8217;s no need to explicitly define the interface of your objects <img src='http://www.indiangeek.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
<p>Note: In Objective-C the interface confusion doesn&#8217;t exist as explicit interfaces are called Protocols. This is a much better name for explicit interfaces. If you have the opportunity I&#8217;d recommend learning this language as it embodies a lot of the ideas from Smalltalk, in a natively compiled language.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
