<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://msmvps.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>Jon Skeet: Coding Blog - All Comments</title><link>http://msmvps.com/blogs/jon_skeet/default.aspx</link><description>C#, .NET, Java, software development etc
**This is my personal blog. The views expressed on these pages are mine alone and not those of my employer.**</description><dc:language>en</dc:language><generator>CommunityServer 2008.5 SP2 (Build: 40407.4157)</generator><item><title>re: Book Review: Async in C# 5.0</title><link>http://msmvps.com/blogs/jon_skeet/archive/2013/05/21/book-review-async-in-c-5-0.aspx#1831124</link><pubDate>Wed, 22 May 2013 12:58:28 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1831124</guid><dc:creator>skeet</dc:creator><description>&lt;p&gt;@Chris: Thanks, missed that. (I wrote the review on a plane, so left all the links as FIXME, then fixed up *most* of them later.) I&amp;#39;ve added the link now.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1831124" width="1" height="1"&gt;</description></item><item><title>re: Book Review: Async in C# 5.0</title><link>http://msmvps.com/blogs/jon_skeet/archive/2013/05/21/book-review-async-in-c-5-0.aspx#1830977</link><pubDate>Tue, 21 May 2013 15:23:20 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1830977</guid><dc:creator>Chris Simpson</dc:creator><description>&lt;p&gt;Hi Jon, thanks for the review. The play books link just goes to &amp;quot;fixme&amp;quot;. Cheers, Chris&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1830977" width="1" height="1"&gt;</description></item><item><title>re: New tool to play with: SemanticMerge</title><link>http://msmvps.com/blogs/jon_skeet/archive/2013/04/18/new-tool-to-play-with-semanticmerge.aspx#1829612</link><pubDate>Tue, 07 May 2013 16:48:49 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1829612</guid><dc:creator>Dim2D</dc:creator><description>&lt;p&gt;Skeet please do blog more, you&amp;#39;re a huge inspiration for a lot of us, I&amp;#39;ve read your awesome book and watched the tekpub vids and learned so much. Keep up the good work.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1829612" width="1" height="1"&gt;</description></item><item><title>re: Fun with Object and Collection Initializers</title><link>http://msmvps.com/blogs/jon_skeet/archive/2013/02/14/fun-with-object-and-collection-initializers.aspx#1829058</link><pubDate>Wed, 01 May 2013 05:12:29 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1829058</guid><dc:creator>Bill Woodruff</dc:creator><description>&lt;p&gt;That first example of &amp;quot;incidental&amp;quot; Property initialization by use of the assignment operator, while creating an instance of an IEnumerable was surprising to me:&lt;/p&gt;
&lt;p&gt;Weird weird = new Weird { Foo = &amp;quot;y&amp;quot; }; &lt;/p&gt;
&lt;p&gt;It wasn&amp;#39;t surprising I couldn&amp;#39;t access the internal collection of &amp;#39;weird, since there&amp;#39;s no &amp;quot;real&amp;quot; GetEnumerator implemented.&lt;/p&gt;
&lt;p&gt;So, with the second call you have created a collection with 1 member, but you can&amp;#39;t access it ! I am not sure what I am supposed to learn from that :)&lt;/p&gt;
&lt;p&gt;What would seem to make sense to me would be that anytime I create a Class meant to be an Enumerator, that maintained some Public state Properties, which might be initialized as instances of the Class are created, that I would put a constructor in the Class to handle initialization of those Properties.&lt;/p&gt;
&lt;p&gt;public Weird(string foo){Foo = foo;}&lt;/p&gt;
&lt;p&gt;Then I can easily create a new instance in which the initialization of state variables, and the creation of internal Enumerable elements, is semantically distinct:&lt;/p&gt;
&lt;p&gt;Weird weird = new Weird(foo:&amp;quot;some string&amp;quot;){&amp;quot;1&amp;quot;,&amp;quot;2&amp;quot;};&lt;/p&gt;
&lt;p&gt;Or, create an instance with state variable set, but internal collection empty:&lt;/p&gt;
&lt;p&gt;Weird weird = new Weird(foo:&amp;quot;some string&amp;quot;);&lt;/p&gt;
&lt;p&gt;That does &amp;quot;lock me into&amp;quot; having to provide an argument(s) to create an instance of &amp;#39;Weird, unless I throw in an optional parameterless calling form:&lt;/p&gt;
&lt;p&gt;public Weird(){}&lt;/p&gt;
&lt;p&gt;thanks, Bill&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1829058" width="1" height="1"&gt;</description></item><item><title>re: New tool to play with: SemanticMerge</title><link>http://msmvps.com/blogs/jon_skeet/archive/2013/04/18/new-tool-to-play-with-semanticmerge.aspx#1827764</link><pubDate>Fri, 19 Apr 2013 08:01:03 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1827764</guid><dc:creator>Richard</dc:creator><description>&lt;p&gt;If you&amp;#39;re looking for novel uses for Roslyn then I&amp;#39;d recommend using it as a code re-writing tool.&lt;/p&gt;
&lt;p&gt;I used it do a large refactoring over 200 files. &amp;nbsp;The change involved removing about 4 properties including regions and comments, inheriting from a newly created base class and passing the value of those 4 properties into the constructor for the base class.&lt;/p&gt;
&lt;p&gt;There were a few edge cases that it didn&amp;#39;t catch but it did the bulk of the work and I cleaned up the remaining code by hand.&lt;/p&gt;
&lt;p&gt;If you were really ambitious I&amp;#39;m sure you could use it to implement a kind of compile time AOP (inserting the AOP stuff in code rather than in CIL) but I haven&amp;#39;t had a need for doing that so I haven&amp;#39;t looked at it.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1827764" width="1" height="1"&gt;</description></item><item><title>re: New tool to play with: SemanticMerge</title><link>http://msmvps.com/blogs/jon_skeet/archive/2013/04/18/new-tool-to-play-with-semanticmerge.aspx#1827733</link><pubDate>Thu, 18 Apr 2013 21:57:24 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1827733</guid><dc:creator>Luis de Santiago</dc:creator><description>&lt;p&gt;Recently I have been interested in Roslyn, and I&amp;#39;m amazed about the possibilities it offers. I have in mind some search integrated in visual studio. But with semantics. R# have a little in that direction, but I think I can go way deeper.&lt;/p&gt;
&lt;p&gt;So this one is a really awesome idea of a product. Will try to tell my comrades to use it.&lt;/p&gt;
&lt;p&gt;By the way. Awesome book &amp;nbsp;(C# in depth 3rd ed. MEAP) :)&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1827733" width="1" height="1"&gt;</description></item><item><title>re: The Open-Closed Principle, in review</title><link>http://msmvps.com/blogs/jon_skeet/archive/2013/03/15/the-open-closed-principle-in-review.aspx#1827714</link><pubDate>Thu, 18 Apr 2013 15:35:59 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1827714</guid><dc:creator>ProfessorZ</dc:creator><description>&lt;p&gt;@Haacked &amp;quot;Clearly it had to be called the &amp;quot;Open Closed Principle&amp;quot; to provide the &amp;quot;O&amp;quot; in &amp;quot;SOLID&amp;quot;.&amp;quot;&lt;/p&gt;
&lt;p&gt;Or really, how is &amp;quot;Liskov substitution principle&amp;quot; not clear to you?&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1827714" width="1" height="1"&gt;</description></item><item><title>re: The Open-Closed Principle, in review</title><link>http://msmvps.com/blogs/jon_skeet/archive/2013/03/15/the-open-closed-principle-in-review.aspx#1826740</link><pubDate>Sun, 07 Apr 2013 06:05:13 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1826740</guid><dc:creator>Philip Schwarz</dc:creator><description>&lt;p&gt;The following post by Kent Beck should help understand the Open-Closed principle:&lt;a rel="nofollow" target="_new" href="http://www.threeriversinstitute.org/blog/?p=242"&gt;www.threeriversinstitute.org/blog&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Here are some excerpts:&lt;/p&gt;
&lt;p&gt;The Open/Closed Principle always bothered me. I agree with it philosophically–good designs make it possible to add functionality without disturbing existing features–but in my experience there are no permanently closed abstractions.&lt;/p&gt;
&lt;p&gt;...&lt;/p&gt;
&lt;p&gt;Ordinary design is the kind we do every day–extract a method, extract an object, move a bit of logic or state closer to where it belongs. The open/closed principle pretty much works. Superclasses sit. APIs sit. New features fit the design without much change.&lt;/p&gt;
&lt;p&gt;Then comes a feature that really doesn’t fit the design. The fundamental elements and relationships have to be twisted to implement it. The fact (feature) just doesn’t fit the theory (design).&lt;/p&gt;
&lt;p&gt;...&lt;/p&gt;
&lt;p&gt;When the need for design change becomes apparent, software designers can isolate the part of the system that is to change from the part that will remain stable.&lt;/p&gt;
&lt;p&gt;...&lt;/p&gt;
&lt;p&gt;Revolutionizing designs without first isolating change puts a bigger burden on the designer. The challenges of revolutionizing a design while working in safe steps is generally enough for me without adding the challenge of keeping track of changes all over the code base. Isolating change is low-risk and fairly mechanical, while giving me an overview of areas of the system that are about to be overhauled.&lt;/p&gt;
&lt;p&gt;...&lt;/p&gt;
&lt;p&gt;Revolutionary design violates the open/closed principle, almost by definition. The feature you want to add needs new elements and relationships that don’t fit with the existing design. The basic abstractions need to be reopened to modification. Once the feature is added, they can close again. Further development can use the new elements and relationships as vocabulary for further extension. This extension takes place against a background of ordinary responsive design.&lt;/p&gt;
&lt;p&gt;...&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1826740" width="1" height="1"&gt;</description></item><item><title>re: Fun with Object and Collection Initializers</title><link>http://msmvps.com/blogs/jon_skeet/archive/2013/02/14/fun-with-object-and-collection-initializers.aspx#1826600</link><pubDate>Fri, 05 Apr 2013 09:13:32 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1826600</guid><dc:creator>Anthony Chambers</dc:creator><description>&lt;p&gt;Interesting. I thought that you were saying weird.Foo was somehow being set to null in your last example (the &amp;#39;result&amp;#39; of assigning a value to the local variable). But when I gave Weird.Foo a default value of &amp;quot;a&amp;quot; it remains as &amp;quot;a&amp;quot;, which is what you were saying all along!&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1826600" width="1" height="1"&gt;</description></item><item><title>re: C# in Depth 3rd edition available for early access, plus a discount code…</title><link>http://msmvps.com/blogs/jon_skeet/archive/2013/02/16/c-in-depth-3rd-edition-available-for-early-access-plus-a-discount-code.aspx#1825895</link><pubDate>Wed, 27 Mar 2013 01:44:43 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1825895</guid><dc:creator>John</dc:creator><description>&lt;p&gt;I had your book, CLR via C# and Expert C# 5.0 (new book but with some interesting information). My collection is about to complete :)&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1825895" width="1" height="1"&gt;</description></item><item><title>re: The Open-Closed Principle, in review</title><link>http://msmvps.com/blogs/jon_skeet/archive/2013/03/15/the-open-closed-principle-in-review.aspx#1825750</link><pubDate>Sun, 24 Mar 2013 00:38:44 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1825750</guid><dc:creator>Philip Schwarz</dc:creator><description>&lt;p&gt;Free screencast: Refactoring to the Open-Closed &lt;a rel="nofollow" target="_new" href="http://www.netobjectives.com/resources/webinars/refactoring-to-open-closed"&gt;www.netobjectives.com/.../refactoring-to-open-closed&lt;/a&gt;&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1825750" width="1" height="1"&gt;</description></item><item><title>re: The Open-Closed Principle, in review</title><link>http://msmvps.com/blogs/jon_skeet/archive/2013/03/15/the-open-closed-principle-in-review.aspx#1825444</link><pubDate>Tue, 19 Mar 2013 00:52:37 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1825444</guid><dc:creator>Richard Smith</dc:creator><description>&lt;p&gt;I&amp;#39;m delighted that u never fully &amp;quot;got&amp;quot; OCP either. &lt;/p&gt;
&lt;p&gt;It did seem that an awful lot of people were repeating this mantra like (cough...cutting and pasting from the original source), and not really getting it themselves either!&lt;/p&gt;
&lt;p&gt;The PV explication makes much more sense to me.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1825444" width="1" height="1"&gt;</description></item><item><title>re: The Open-Closed Principle, in review</title><link>http://msmvps.com/blogs/jon_skeet/archive/2013/03/15/the-open-closed-principle-in-review.aspx#1825439</link><pubDate>Mon, 18 Mar 2013 22:25:25 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1825439</guid><dc:creator>Michael Hunter</dc:creator><description>&lt;p&gt;You mention that in the Shape example there is only predicted variation. I would argue though, that the example also implicitly predicts something that won&amp;#39;t vary: the operations that can be done on a shape (eg &amp;quot;Draw&amp;quot;). If the point/location of variation was not &amp;quot;what shapes there are&amp;quot; but rather &amp;quot;what operations can be done on a shape&amp;quot; then the DrawAllShapes with a switch statement is clearly the better solution. It is OPEN for EXTENSION [of functionality] because new operations can be added (eg create a &amp;quot;measure area&amp;quot; function) and CLOSED for MODIFICATION because new shapes can&amp;#39;t be added easily. In other words, it&amp;#39;s not just a case of &amp;quot;more&amp;quot; or &amp;quot;less&amp;quot; variability, but also where you put it. In this case one type of variability sacrifices another type. You have to decide at design time whether the program is more likely to expand with new types of shapes, or new operations on a fixed set of shape types.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1825439" width="1" height="1"&gt;</description></item><item><title>re: The Open-Closed Principle, in review</title><link>http://msmvps.com/blogs/jon_skeet/archive/2013/03/15/the-open-closed-principle-in-review.aspx#1825387</link><pubDate>Mon, 18 Mar 2013 02:07:47 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1825387</guid><dc:creator>Keith Nicholas</dc:creator><description>&lt;p&gt;Really worth reading Object-Oriented Software Construction, and understanding Bertrands ideas on OOP. &amp;nbsp;Back in the very early 90s I learnt OO using Eiffel. &amp;nbsp;As I see it, the ideas of OCP marries up with Design By Contract for making robust modular software (as well as other principles). &amp;nbsp; The idea being you make these ecosystems of objects (which Eiffel was really big on) which have well defined thoughtfully designed contracts, you can then build on these objects to make more complex systems. &amp;nbsp;It&amp;#39;s essential that these objects are well designed and stable, and hence conform to OCP. This is because you want to be able share these objects as a base for many kinds of software systems so other people can build robust software with whatever you come up with. &amp;nbsp;So the code should be closed to change, except when there was bugs, but in general if you have well designed contracts, your software should be quite robust. &amp;nbsp;Its like an engineering approach to software where you&amp;#39;d end up making these well designed objects that are **eternally** useful made to a particular specification and tolerance that were usable as parts in a bigger machine.&lt;/p&gt;
&lt;p&gt;The reality is, from greenfield, designing software like this was quite difficult. &amp;nbsp;Implementation inheritance was a popular way to &amp;quot;extend&amp;quot;. Messes were made. So what was needed was a lot more practical advice on OO designs that worked well, the principles were too broad (but guiding). Then slowly practical advice appeared over the years. The GOF patterns being of a major practical help, and then eventually unit testing as a practical way of having executable coding contracts, and Refactoring for a way of morphing software without having to get it all correct with engineering precision upfront. &amp;nbsp;Then with this base, in the 2000s a massive melting pot of ideas came along.&lt;/p&gt;
&lt;p&gt;However, the core principle of OCP lives on..... just having various postmodern reinterpretations :) &amp;nbsp;&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1825387" width="1" height="1"&gt;</description></item><item><title>re: The Open-Closed Principle, in review</title><link>http://msmvps.com/blogs/jon_skeet/archive/2013/03/15/the-open-closed-principle-in-review.aspx#1825359</link><pubDate>Sun, 17 Mar 2013 13:50:29 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1825359</guid><dc:creator>skeet</dc:creator><description>&lt;p&gt;@Philip: As I said before, I don&amp;#39;t think the comments here are a good medium for actual discussion. I don&amp;#39;t think it would be fruitful for me to try to reply to you point by point here.&lt;/p&gt;
&lt;p&gt;I suggest you either start a Discourse conversation (and include a reference here) or let me know if we&amp;#39;re likely to be at the same conference at any point - a conversation is likely to be much more fruitful.&lt;/p&gt;
&lt;p&gt;However, I&amp;#39;d ask you to keep bearing in mind that we&amp;#39;re talking about a principle which many, many people will hear about *without* having read every other thing that the authors have written about. If a summary gives the wrong impression until you&amp;#39;re read not just the single paper in front of you but also umpteen other books, I&amp;#39;d still say it&amp;#39;s a bad summary.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1825359" width="1" height="1"&gt;</description></item><item><title>re: The Open-Closed Principle, in review</title><link>http://msmvps.com/blogs/jon_skeet/archive/2013/03/15/the-open-closed-principle-in-review.aspx#1825358</link><pubDate>Sun, 17 Mar 2013 13:30:28 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1825358</guid><dc:creator>Philip Schwarz</dc:creator><description>&lt;p&gt;Jon, you said: &amp;quot;Likewise the meaning of &amp;quot;open for extension&amp;quot; seems unusual to me. I&amp;#39;d argue that the intuitive meaning is &amp;quot;can be extended&amp;quot; – where the use of the term &amp;quot;extended&amp;quot; certainly nods towards inheritance, even if it&amp;#39;s not intended meaning. If the idea is &amp;quot;we can make the module behave differently&amp;quot; – as Uncle Bob&amp;#39;s description suggests – then &amp;quot;open for extension&amp;quot; is a very odd way of expressing that idea.&amp;quot;&lt;/p&gt;
&lt;p&gt;Could it be that the reason you strongly associate the word extension/extending with inheritance is because:&lt;/p&gt;
&lt;p&gt;(1) In Meyer&amp;#39;s formulation of the OCP, implementation inheritance plays a key role&lt;/p&gt;
&lt;p&gt;(2) languages like Java and C# use the keyword &amp;#39;extends&amp;#39; to signify implementation inheritance?&lt;/p&gt;
&lt;p&gt;Let me elaborate on these two points.&lt;/p&gt;
&lt;p&gt;(1) While implementation inheritance is central to Meyer&amp;#39;s formulation of the OCP, in Robert Martin&amp;#39;s formulation, the role of implementation inheritance is almost completely eliminated in favour of interface inheritance, in the same sense that the Gang of Four&amp;#39;s design patterns are largely about replacing implementation inheritance with interface inheritance.&lt;/p&gt;
&lt;p&gt;In ASDPPP, Martin says that the Template Method pattern, and the Strategy pattern are the most common way of satisfying the OCP. Template Method is less desirable because it one of the few patterns that uses implementation inheritance (in Martin&amp;#39;s words in ASDPPP: it only conforms to half of the DIP principle). Startegy is more desirable because like the majority of patterns it uses interface inheritance (it fully conforms to the DIP principle).&lt;/p&gt;
&lt;p&gt;Just in case you have not read the &amp;#39;Class versus Interface Inheritance&amp;#39; section in the GoF&amp;#39;s Design Patterns book, here is my summary:&lt;/p&gt;
&lt;p&gt;* It&amp;#39;s important to understand the difference between an object&amp;#39;s class and its type.&lt;/p&gt;
&lt;p&gt;* An object&amp;#39;s class defines how the object is implemented (state and operation-implementation).&lt;/p&gt;
&lt;p&gt;* An object&amp;#39;s type only refers to its interface - the set of requests to which it can respond.&lt;/p&gt;
&lt;p&gt;* An object can have many types, and objects of different classes can have the same type.&lt;/p&gt;
&lt;p&gt;* Because a class defines the operations it can perform, it also defines the object&amp;#39;s type.&lt;/p&gt;
&lt;p&gt;* Languages like C++ and Eiffel use classes to specify both an object&amp;#39;s type and it&amp;#39;s implementation. Smalltalk programs don&amp;#39;t declare the types of variables.&lt;/p&gt;
&lt;p&gt;* It&amp;#39;s also important to understand the difference between class inheritance and interface inheritance (or subtyping). Class inheritance defines an object&amp;#39;s implementation in terms of another object&amp;#39;s implementation. In short, it&amp;#39;s a mechanism for code and representation sharing. In contrast, interface inheritance (or subtyping) describes when an object can be used in place of another.&lt;/p&gt;
&lt;p&gt;* It&amp;#39;s easy to confuse these two concepts, because many languages don&amp;#39;t support the distinction between interface and implementation inheritance. In languages like C++ and Eiffel, inheritance means both interface and implementation inheritance. [...] In Smalltalk, inheritance means just implementation interface.&lt;/p&gt;
&lt;p&gt;* Although most programming languages don&amp;#39;t support the distinction between interface and implementation inheritance, people make the distinction in practice&lt;/p&gt;
&lt;p&gt;* Many of the design patterns depend on this distinction.&lt;/p&gt;
&lt;p&gt;In Robert Martin&amp;#39;s formulation of the OCP, we use mainly interface inheritance (but not exclusively - there are some cases in which implementation inheritance is used) to extend the behaviour of a class by adding new code rather than modifying the class.&lt;/p&gt;
&lt;p&gt;(2) In Dale Skrien&amp;#39;s great book, &amp;quot;OO design using Java&amp;quot; (btw don&amp;#39;t be put off by the word &amp;#39;Java&amp;#39;), he says that one way to measure the quality of a design is to analyse s/w with regard to the following properties, which he calls &amp;quot;the criteria for elegant software&amp;quot;:&lt;/p&gt;
&lt;p&gt;USABILITY - is it easy for the client to use&lt;/p&gt;
&lt;p&gt;COMPLETENESS - does it satisfy all the client&amp;#39;s needs&lt;/p&gt;
&lt;p&gt;ROBUSTNESS - will it deal with unusual situations gracefully and avoid crashing?&lt;/p&gt;
&lt;p&gt;EFFICIENCY - will it perform the necessary computations in a reasonable amount of time and using a reasonable amount of memory and other resources?&lt;/p&gt;
&lt;p&gt;SCALABILITY - will it still perform correctly and efficiently when the problems grow in size by several orders of magnitude&lt;/p&gt;
&lt;p&gt;READABILITY - is it easy for another programmer to read and understand the design and code?&lt;/p&gt;
&lt;p&gt;REUSABILITY - can it be reused in another completely different setting?&lt;/p&gt;
&lt;p&gt;SIMPLICITY - is the design and/or the implementation unnecessarily complex?&lt;/p&gt;
&lt;p&gt;MAINTAINABILITY - can defects be found and fixed easily without adding new defects?&lt;/p&gt;
&lt;p&gt;EXTENSIBILITY - can it easily be enhanced or restricted by adding new features or removing old features without breaking code?&lt;/p&gt;
&lt;p&gt;Is it unreasonable in your mind for Martin&amp;#39;s formulation of the OCP to use the word &amp;#39;extends&amp;#39; in the above sense?&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1825358" width="1" height="1"&gt;</description></item><item><title>re: The Open-Closed Principle, in review</title><link>http://msmvps.com/blogs/jon_skeet/archive/2013/03/15/the-open-closed-principle-in-review.aspx#1825346</link><pubDate>Sun, 17 Mar 2013 09:39:17 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1825346</guid><dc:creator>skeet</dc:creator><description>&lt;p&gt;@Philip: Thanks for the detailed comments. I don&amp;#39;t think this is the best medium to have a full debate about them (Discourse, perhaps?).&lt;/p&gt;
&lt;p&gt;I still need to read through your comments more carefully (I&amp;#39;ve only skimmed so far) but one thing that nothing seems to change is that the broad statement of OCP itself is confusing, and uses words (particularly &amp;quot;open&amp;quot; and &amp;quot;closed&amp;quot;) in a way which is counter to their normal uses.&lt;/p&gt;
&lt;p&gt;As such, I wouldn&amp;#39;t *want* to write my own explanation of OCP - I&amp;#39;d rather start again from scratch than try to put another set of details behind a phrasing which I feel is fatally flawed to begin with.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1825346" width="1" height="1"&gt;</description></item><item><title>re: The Open-Closed Principle, in review</title><link>http://msmvps.com/blogs/jon_skeet/archive/2013/03/15/the-open-closed-principle-in-review.aspx#1825336</link><pubDate>Sun, 17 Mar 2013 02:24:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1825336</guid><dc:creator>Philip Schwarz</dc:creator><description>&lt;p&gt;Jon, you said: &amp;quot;Most of the principles seem pretty reasonable to me – but I&amp;#39;ve never &amp;quot;got&amp;quot; the open-closed principle&amp;quot;&lt;/p&gt;
&lt;p&gt;Odd since according to Kirk Knoernschild the other principles are derived from the OCP.&lt;/p&gt;
&lt;p&gt;E.g. #1 &amp;quot;We can think of LSP as an extension to OCP. In order to take advantage of LSP, we must adhere to OCP because violations of LSP are violations of OCP, but not vice versa.&lt;/p&gt;
&lt;p&gt;E.g #2 &amp;quot;DIP tells us how to we can adhere to OCP...if OCP is the desired end, DIP is the means through which we achieve that end...in order to adhere to OCP, we must first take advantage of DIP.&amp;quot;&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1825336" width="1" height="1"&gt;</description></item><item><title>re: The Open-Closed Principle, in review</title><link>http://msmvps.com/blogs/jon_skeet/archive/2013/03/15/the-open-closed-principle-in-review.aspx#1825335</link><pubDate>Sun, 17 Mar 2013 01:47:52 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1825335</guid><dc:creator>Philip Schwarz</dc:creator><description>&lt;p&gt;Jon, you said: &amp;quot;There&amp;#39;s a reasonable example of a function which is asked to draw a collection of shapes: the bad code is aware of all the types of shape available, and handles each one separately. The good code uses an abstraction where each shape (Circle, Square) knows how to draw itself and inherits from a common base class (Shape). Great stuff... but what&amp;#39;s that got to do with what was described above? How are the concepts of &amp;#39;open&amp;#39; and &amp;#39;closed&amp;#39; clarified?&amp;quot;&lt;/p&gt;
&lt;p&gt;Does the following help at all?:&lt;/p&gt;
&lt;p&gt;The bad code (version one of function DrawAllShapes) knows all the types of shape available, so to get the function to handle a new shape, you have to modify the function: you have to change it so that it knows about the new type. So while the bad code is open to extension, i.e. it can be enhanced so that it handles a new type, it is NOT closed against the addition of new shapes, because doing so requires you to open up the function and change it. &lt;/p&gt;
&lt;p&gt;The good code (the second version of function DrawAllShapes) however does not know all the types of shape available. It only knows about the abstraction that is the Shape interface. To get the good code to handle a new shape, you do NOT need to open up the function and modify it. &amp;nbsp;All you need to do is add new code, by writing a new class that implements the shape interface and that represents the new type of shape. &lt;/p&gt;
&lt;p&gt;So the good code is both open for extension i.e. it can be enhanced so that it handles a new type, and closed against the addition of new types of shape, because you don&amp;#39;t need to open it up and change it: it stays closed, but by adding new code (the new class) you extend its behaviour.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1825335" width="1" height="1"&gt;</description></item><item><title>re: The Open-Closed Principle, in review</title><link>http://msmvps.com/blogs/jon_skeet/archive/2013/03/15/the-open-closed-principle-in-review.aspx#1825331</link><pubDate>Sun, 17 Mar 2013 00:03:01 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1825331</guid><dc:creator>Philip Schwarz</dc:creator><description>&lt;p&gt;Jon, you said: &amp;quot;the description of Meyer&amp;#39;s approach to &amp;#39;make a change by extending a class&amp;#39; feels like a ghastly abuse of inheritance to me&amp;quot;&lt;/p&gt;
&lt;p&gt;Meyer is fully aware that this is a bit of a hack, in fact he says that &amp;quot;one way to describe the open-closed principle and the consequent OO techniques, … is to think of them as ORGANIZED HACKING...instead of a normal hack, in which A is polluted with ‘if (that_special_case) then’...the organized form of hacking enables us to cater to the variants… without affecting the consistency of the original&amp;quot;&lt;/p&gt;
&lt;p&gt;Meyer does tell developers that:&lt;/p&gt;
&lt;p&gt;(1) If you have control over original s/w and can rewrite it so that it will address the needs of several kinds of clients, at no extra complication, …you should do so&lt;/p&gt;
&lt;p&gt;(2) The OCP principle and associated techniques are intended for the adaptation of healthy modules: neither OCP nor redefinition in inheritance is a way to address design flaws, let alone bugs. If there is something wrong with a module you should fix it…not leave the original alone and try to correct the problem in the derived module.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1825331" width="1" height="1"&gt;</description></item></channel></rss>