<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>API Design Myth: Interface as Contract</title><link>http://blogs.msdn.com/kcwalina/archive/2004/10/24/246947.aspx</link><description>I often hear people saying that interfaces specify contracts. I believe this is a dangerous myth. Interfaces, by themselves, do not specify much beyond the syntax required to use an object. The interface-as-contract myth causes people to do the wrong</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: API Design Myth: Interface as Contract</title><link>http://blogs.msdn.com/kcwalina/archive/2004/10/24/246947.aspx#247301</link><pubDate>Mon, 25 Oct 2004 20:27:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:247301</guid><dc:creator>Frank Hileman</dc:creator><description>I always thought the real problem was the change in the meaning of the word &amp;quot;interface&amp;quot;: it used to mean contract. Then after interfaces were added to languages, such as the C# concept of interface, the word became tied to a specific type of interface. It was no longer generic.&lt;br&gt;&lt;br&gt;I still use the word &amp;quot;interface&amp;quot; to mean &amp;quot;contract&amp;quot; in conversation sometimes, but it cause a lot of confusion. People assume I mean a C#-type interface. So I must specify contract.... :(</description></item><item><title>re: API Design Myth: Interface as Contract</title><link>http://blogs.msdn.com/kcwalina/archive/2004/10/24/246947.aspx#247372</link><pubDate>Mon, 25 Oct 2004 22:18:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:247372</guid><dc:creator>Daniel Moth</dc:creator><description>As soon as you went into the example my brain told me I was about to encounter postcondition syntax...but I didn't. Are you guys even remotely considering adding some pre/post-condition support and invariants much like what Eiffel offers? Only then, I think, we would really be talking about contracts.</description></item><item><title>New </title><link>http://blogs.msdn.com/kcwalina/archive/2004/10/24/246947.aspx#248285</link><pubDate>Wed, 27 Oct 2004 04:23:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:248285</guid><dc:creator>OdeToCode Link Blog</dc:creator><description /></item><item><title>re: API Design Myth: Interface as Contract</title><link>http://blogs.msdn.com/kcwalina/archive/2004/10/24/246947.aspx#249470</link><pubDate>Fri, 29 Oct 2004 10:27:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:249470</guid><dc:creator>Muhammad Abubakar</dc:creator><description>Actually the way you have described a contract is not how its described as all over in the msdn. I think that is why we, the readers of msdn, fall victim of this myth. I'm going to refer *some* of the places where I thought that interface is a contract(words between &amp;quot;---&amp;gt;&amp;lt;---&amp;quot; are excerpts from the msdn pages/articles):&lt;br&gt;page:ms-help://MS.MSDNQTR.2003FEB.1033/dncomg/html/msdn_design.htm ---&amp;gt;&lt;br&gt;Each interface must have a GUID that serves as its programmatic name. It is this interface ID (IID) that uniquely identifies the contract defined by the interface. After an interface design with a particular IID is published, the specifics of all the other elements (described in detail below) that make up that interface cannot change . . . ever. (By published, we mean implemented in a binary component and &amp;quot;released&amp;quot; to another party to use.) &amp;lt;---&lt;br&gt;&lt;br&gt;---&amp;gt;A rigid contract requires that all methods be fully implemented.&amp;lt;---&lt;br&gt;&lt;br&gt;page:ms-help://MS.MSDNQTR.2003FEB.1033/dndotnet/html/callnetfrcom.htm&lt;br&gt;---&amp;gt;The contract says that the class will implement all of the members of the interface. It may also contain additional members that are not part of the interface, but you'll get an error if you try to build a class that does not completely implement an interface.&lt;br&gt;&amp;lt;---&lt;br&gt;while defining the &amp;quot;Interface Inheritance&amp;quot; the article says ---&amp;gt;When you want to create an abstract class, you use the keyword Interface instead of Class. You give the interface a name, and define each of the properties and methods that you expect a subclass to implement. The reason you do this is that there is nothing in the base class that would make sense to implement—it only contains generic data without methods. You are just creating a contract that says any subclass using this interface must adhere to certain rules.&amp;lt;---&lt;br&gt;what are those rules? the logic that should be found in the implementation of the interface in a class OR just following a syntax?&lt;br&gt;&lt;br&gt;page:ms-help://MS.MSDNQTR.2003FEB.1033/vbcn7/html/vaconInterfacesInVisualBasic70.htm&lt;br&gt;---&amp;gt;An interface represents a contract, in that a class that implements an interface must implement every aspect of that interface exactly as it is defined.&amp;lt;---&lt;br&gt;---&amp;gt;If you think of an interface as a contract, it is clear that both sides of the contract have a role to play. The publisher of an interface agrees never to change that interface, and the implementer agrees to implement the interface exactly as it was designed.&amp;lt;---&lt;br&gt;&lt;br&gt;So I always thought that they are only talking about function-signatures/syntax.</description></item><item><title>Tell me where it hurts</title><link>http://blogs.msdn.com/kcwalina/archive/2004/10/24/246947.aspx#351512</link><pubDate>Wed, 12 Jan 2005 19:47:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:351512</guid><dc:creator>maps and legends</dc:creator><description>One of my favorite development practices is stubbing things out. I don't know if I'd go so far as to calling it &amp;quot;mocks&amp;quot;, or &amp;quot;development by contract&amp;quot;, but it can allow developers with dependancies to move forward until the real subsystem comes on line. But this bring about a corollary favorite development practice: tell me where it hurts. More specifically, if you haven't finished implementing something, but have methods in place, don't just have them return null, or silently exit....</description></item><item><title>re: API Design Myth: Interface as Contract</title><link>http://blogs.msdn.com/kcwalina/archive/2004/10/24/246947.aspx#3115133</link><pubDate>Wed, 06 Jun 2007 14:25:29 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:3115133</guid><dc:creator>Udi Dahan - The Software Simplist</dc:creator><description>&lt;p&gt;I agree that the interface by itself is not enough to specify a contract. I like to write unit tests against my interface in order to specify its dynamic behavior. Then, a build against an implementation will both compile the class against the interface checking its structure, as well as run the tests thus verifying its behavior. I've written about this here:&lt;/p&gt;
&lt;p&gt;&lt;a rel="nofollow" target="_new" href="http://udidahan.weblogs.us/2006/05/06/behavior-specification-the-next-generation-of-unit-testing/"&gt;http://udidahan.weblogs.us/2006/05/06/behavior-specification-the-next-generation-of-unit-testing/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Since you'll want client code to depend only the interface, not on some abstract base class for reasons of extensibility, this approach documents for that client code what assumptions in can make.&lt;/p&gt;
&lt;p&gt;So, I'd have to say that interfaces are a necessary part of the solution, but not sufficient by themselves.&lt;/p&gt;</description></item><item><title>re: API Design Myth: Interface as Contract</title><link>http://blogs.msdn.com/kcwalina/archive/2004/10/24/246947.aspx#3118389</link><pubDate>Wed, 06 Jun 2007 17:58:44 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:3118389</guid><dc:creator>kcwalina</dc:creator><description>&lt;P&gt;Udi, having a set of reference tests for abstractions is a great idea.&lt;/P&gt;
&lt;P&gt;But I don't see why interface gives you more/better extensibility than an abstract class, besides cases where you need "multiple inheritance."&lt;/P&gt;</description></item><item><title>re: API Design Myth: Interface as Contract</title><link>http://blogs.msdn.com/kcwalina/archive/2004/10/24/246947.aspx#8592322</link><pubDate>Thu, 12 Jun 2008 02:02:06 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8592322</guid><dc:creator>deepak N</dc:creator><description>&lt;p&gt;kcwalina, another very &amp;nbsp;good part of interface is we can use it to ensure proper/effective naming in our code.&lt;/p&gt;
&lt;p&gt;if we can identify similarities (properties/functions/events) between related or unrelated classes then we can prepare a interface with those functions/properties and make it a practise to implement appropriate interface when those properties and functions are used. &lt;/p&gt;
&lt;p&gt;this will make sure we are not using different names for similar funtions/ properties&lt;/p&gt;
&lt;p&gt;eg. i may have 3 classes Circle/RoofTop/Carpet&lt;/p&gt;
&lt;p&gt;its usefull to implement IhaveArea interface and then implement the GetArea() function of the Interface. This will make sure even if differnet people are working on the project they all have identical names for similar work. &lt;/p&gt;</description></item><item><title>Interfaces Topic</title><link>http://blogs.msdn.com/kcwalina/archive/2004/10/24/246947.aspx#8876513</link><pubDate>Mon, 18 Aug 2008 17:22:02 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8876513</guid><dc:creator>BrianLei</dc:creator><description>&lt;p&gt;InterfacesWow,在开发时、架构时、思考时，Interfaces都是我们这族人常常使用的，在开发工作中，我常常用Interfaces作为参数类型用于方法的signatures.此贴就...&lt;/p&gt;
</description></item><item><title>Interfaces Topic(zz)</title><link>http://blogs.msdn.com/kcwalina/archive/2004/10/24/246947.aspx#9049463</link><pubDate>Thu, 06 Nov 2008 18:29:37 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9049463</guid><dc:creator>stu_acer</dc:creator><description>&lt;p&gt;InterfacesWow,在开发时、架构时、思考时，Interfaces都是我们这族人常常使用的，&lt;/p&gt;
&lt;p&gt;在开发工作中，我常常用Interfaces作为参数类型用于方法的signatures.&lt;/p&gt;
&lt;p&gt;...&lt;/p&gt;
</description></item></channel></rss>