<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Object Mentor Blog: The Open-Closed Principle for Languages with Open Classes</title>
    <link>http://blog.objectmentor.com/articles/2008/09/04/the-open-closed-principle-for-languages-with-open-classes</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description></description>
    <item>
      <title>The Open-Closed Principle for Languages with Open Classes</title>
      <description>&lt;p&gt;We&amp;#8217;ve been having a discussion inside Object Mentor World Design Headquarters about the meaning of the &lt;span class="caps"&gt;OCP&lt;/span&gt; for dynamic languages, like Ruby, with open classes.&lt;/p&gt;


	&lt;p&gt;For example, in Ruby it&amp;#8217;s normal to define a class or module, &lt;em&gt;e.g.,&lt;/em&gt;&lt;/p&gt;


&lt;pre&gt;
    &lt;code&gt;
# foo.rb
class Foo
    def method1 *args
        ...
    end
end
    &lt;/code&gt;
&lt;/pre&gt;

	&lt;p&gt;and later re-open the class and add (or redefine) methods,&lt;/p&gt;


&lt;pre&gt;
    &lt;code&gt;
# foo2.rb
class Foo
    def method2 *args
        ...
    end
end
    &lt;/code&gt;
&lt;/pre&gt;

	&lt;p&gt;Users of &lt;code&gt;Foo&lt;/code&gt; see all the methods, as if &lt;code&gt;Foo&lt;/code&gt; had one definition.&lt;/p&gt;


&lt;pre&gt;
    &lt;code&gt;
foo = Foo.new
foo.method1 :arg1, :arg2
foo.method2 :arg1, :arg2
    &lt;/code&gt;
&lt;/pre&gt;

	&lt;p&gt;Do open classes violate the Open-Closed Principle? Bertrand Meyer articulated &lt;span class="caps"&gt;OCP&lt;/span&gt;. Here is his definition&lt;sup&gt;&lt;a href="#fn1"&gt;1&lt;/a&gt;&lt;/sup&gt;.&lt;/p&gt;


	&lt;blockquote&gt;
		&lt;p&gt;Software entities (classes, modules, functions, &lt;em&gt;etc.&lt;/em&gt;) should be open for extension, but closed for modification.&lt;/p&gt;
	&lt;/blockquote&gt;


	&lt;p&gt;He elaborated on it &lt;a href="http://se.ethz.ch/~meyer/publications/computer/implicitness.pdf"&gt;here&lt;/a&gt;.&lt;/p&gt;


	&lt;blockquote&gt;
		&lt;p&gt;... This is the open-closed principle, which in my opinion is one of the central innovations of object technology: the ability to use a software component as it is, while retaining the possibility of adding to it later through inheritance. Unlike the records or structures of other approaches, a class of object technology is both closed and open: closed because we can start using it for other components (its clients); open because we can at any time add new properties without invalidating its existing clients.&lt;/p&gt;
	&lt;/blockquote&gt;


	&lt;blockquote&gt;
		&lt;p&gt;&lt;a href="http://se.ethz.ch/~meyer/publications/computer/implicitness.pdf"&gt;Tell Less, Say More: The Power of Implicitness&lt;/a&gt;&lt;/p&gt;
	&lt;/blockquote&gt;


	&lt;p&gt;So, if one client &lt;code&gt;require&lt;/code&gt;&amp;#8217;s only &lt;code&gt;foo.rb&lt;/code&gt; and only uses &lt;code&gt;method1&lt;/code&gt;, that client doesn&amp;#8217;t care what &lt;code&gt;foo2.rb&lt;/code&gt; does. However, if the client also &lt;code&gt;require&lt;/code&gt;&amp;#8217;s &lt;code&gt;foo2.rb&lt;/code&gt;, perhaps indirectly through another &lt;code&gt;require&lt;/code&gt;, problems will ensue unless the client is unaffected by what &lt;code&gt;foo2.rb&lt;/code&gt; does.  This looks a lot like the way &amp;#8220;good&amp;#8221; inheritance should behave.&lt;/p&gt;


	&lt;p&gt;So, the answer is &lt;em&gt;no&lt;/em&gt;, we aren&amp;#8217;t violating &lt;span class="caps"&gt;OCP&lt;/span&gt;, as long as we extend a re-opened class following the same rules we would use when inheriting from it.&lt;/p&gt;


	&lt;p&gt;If we use inheritance instead:&lt;/p&gt;


&lt;pre&gt;
    &lt;code&gt;
# foo.rb
class Foo
    def method1 *args
        ...
    end
end
...
class DerivedFoo &amp;lt; Foo
    def method2 *args
        ...
    end
end
...
foo = SubFoo.new    # Instantiate different class...
foo.method1 :arg1, :arg2
foo.method2 :arg1, :arg2
    &lt;/code&gt;
&lt;/pre&gt;

	&lt;p&gt;One notable difference is that we have to instantiate a different class. This is an important difference. While you can often just use inheritance, and maybe you should prefer it, inheritance only works if you have full control over what types get instantiated and &lt;em&gt;it&amp;#8217;s easy to change which types you use&lt;/em&gt;. Of course, inheritance is also the best approach when you need all behavioral variants &lt;em&gt;simulateneously&lt;/em&gt;, &lt;em&gt;i.e.,&lt;/em&gt; each variant in one or more objects.&lt;/p&gt;


	&lt;p&gt;Sometimes you want to affect the behavior of all instances transparently, without changing the types that are instantiated. A slightly better example, logging method calls, illustrates the point. Here we use the &amp;#8220;famous&amp;#8221; &lt;code&gt;alias_method&lt;/code&gt; in Ruby.&lt;/p&gt;


&lt;pre&gt;
    &lt;code&gt;
# foo.rb
class Foo
    def method1 *args
        ...
    end
end
# logging_foo.rb
class Foo
    alias_method :old_method1, :method1
    def method1 *args
        p "Inside method1(#{args.inspect})" 
        old_method1 *args
    end
end
...
foo = Foo.new
foo.method1 :arg1, :arg2
    &lt;/code&gt;
&lt;/pre&gt;

	&lt;p&gt;&lt;code&gt;Foo.method1&lt;/code&gt; behaves like a subclass override, with extended behavior that still obeys the &lt;a href="http://www.objectmentor.com/resources/articles/lsp.pdf"&gt;Liskov-Substitution Principle&lt;/a&gt; (LSP).&lt;/p&gt;


	&lt;p&gt;So, I think the &lt;span class="caps"&gt;OCP&lt;/span&gt; can be reworded slightly.&lt;/p&gt;


	&lt;blockquote&gt;
		&lt;p&gt;Software entities (classes, modules, functions, &lt;em&gt;etc.&lt;/em&gt;) should be open for extension, but closed for &lt;strong&gt;source&lt;/strong&gt; modification.&lt;/p&gt;
	&lt;/blockquote&gt;


	&lt;p&gt;We should not re-open the original source, but adding functionality through a separate source file is okay.&lt;/p&gt;


	&lt;p&gt;Actually, I prefer a slightly different wording.&lt;/p&gt;


	&lt;blockquote&gt;
		&lt;p&gt;Software entities (classes, modules, functions, &lt;em&gt;etc.&lt;/em&gt;) should be open for extension, but closed for &lt;strong&gt;source and contract&lt;/strong&gt; modification.&lt;/p&gt;
	&lt;/blockquote&gt;


	&lt;p&gt;The extra &lt;strong&gt;and contract&lt;/strong&gt; is redundant with &lt;span class="caps"&gt;LSP&lt;/span&gt;. I don&amp;#8217;t think this kind of redundancy is necessarily bad. ;) The &lt;em&gt;contract&lt;/em&gt; is the set of &lt;em&gt;behavioral expectations&lt;/em&gt; between the &amp;#8220;entity&amp;#8221; and its client(s). Just as it is &lt;a href="http://blog.objectmentor.com/articles/2007/02/17/liskov-substitution-principle-and-the-ruby-core-libraries"&gt;bad to break the contract with inheritance&lt;/a&gt;, it is also bad to break it through open classes.&lt;/p&gt;


	&lt;p&gt;&lt;span class="caps"&gt;OCP&lt;/span&gt; and &lt;span class="caps"&gt;LSP&lt;/span&gt; together are our most important design principles for effective organization of similar &lt;em&gt;vs.&lt;/em&gt; variant behaviors. Inheritance is one way we do this. Open classes provide another way. Aspects provide a third way and are subject to the same &lt;a href="http://www.aosd.net/2007/program/industry/I6-AspectDesignPrinciples.pdf"&gt;design issues&lt;/a&gt;.&lt;/p&gt;


	&lt;p id="fn1"&gt;&lt;sup&gt;1&lt;/sup&gt; Meyer, Bertrand (1988). Object-Oriented Software Construction. Prentice Hall. &lt;span class="caps"&gt;ISBN 0136290493&lt;/span&gt;.&lt;/p&gt;</description>
      <pubDate>Thu, 04 Sep 2008 21:42:00 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:8045ef44-c256-4c10-9edf-7f9fde4a26bd</guid>
      <author>Dean Wampler</author>
      <link>http://blog.objectmentor.com/articles/2008/09/04/the-open-closed-principle-for-languages-with-open-classes</link>
      <category>Dean's Deprecations</category>
      <category>Dynamic Languages</category>
      <category>Design Principles</category>
      <category>Clean Code</category>
      <category>OCP</category>
      <category>languages</category>
      <category>Ruby</category>
    </item>
    <item>
      <title>"The Open-Closed Principle for Languages with Open Classes" by Brett L. Schuchert</title>
      <description>&lt;p&gt;What happens if the class itself performs the extensions? For example, using some kind of rule (e.g. naming convention), it finds all of its extensions and &amp;#8220;loads&amp;#8221; them once and for all?&lt;/p&gt;


	&lt;p&gt;The class is closed &amp;#8211; source not changing.&lt;/p&gt;


	&lt;p&gt;The opening up of the class is defined in one place (the class itself) but the extension of the class can be determined by the source code (to Feathers point).&lt;/p&gt;


	&lt;p&gt;I&amp;#8217;ve got such an example I&amp;#8217;m working with (a simple one sure).&lt;/p&gt;


	&lt;p&gt;About the only thing I&amp;#8217;d want to add is that the extension point verifies that the other &amp;#8220;openings&amp;#8221; don&amp;#8217;t step on each other.&lt;/p&gt;</description>
      <pubDate>Sat, 06 Sep 2008 13:37:44 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:9cc54c4e-76aa-4c63-b85d-3646cb6945f5</guid>
      <link>http://blog.objectmentor.com/articles/2008/09/04/the-open-closed-principle-for-languages-with-open-classes#comment-2038</link>
    </item>
    <item>
      <title>"The Open-Closed Principle for Languages with Open Classes" by Dean Wampler</title>
      <description>&lt;p&gt;@Glenn and @MichaelFeathers, agreed that &amp;#8220;nullification&amp;#8221; or &amp;#8220;throw-a-curve-ball-ification&amp;#8221; are no no&amp;#8217;s.&lt;/p&gt;


	&lt;p&gt;One of the problems I&amp;#8217;ve thought a lot about lately is how an &amp;#8220;optimal&amp;#8221; domain model is only optimal in a narrow context. In the large enterprises I work with, different subsystems and parts of the business need the same type to have different attributes and behaviors. It&amp;#8217;s something of a lose-lose for the designer. If the type has the superset of stuff, that&amp;#8217;s bad. If we have lots of variants of the type (with boilerplate copying back and forth), that&amp;#8217;s bad for different reasons.&lt;/p&gt;


	&lt;p&gt;I want a way to keep a consistent, universal domain model, yet provide context-dependent extensions, even to shared instances. That and world peace&amp;#8230;.&lt;/p&gt;


	&lt;p&gt;By the way, the aspect-oriented programming community has wrestled a lot with ways to specify allowed extension points to a type without assuming anything (or much) about the actual extensions.&lt;/p&gt;</description>
      <pubDate>Fri, 05 Sep 2008 19:05:04 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:e45731ba-cc3d-4230-8d57-f50ac2126d6b</guid>
      <link>http://blog.objectmentor.com/articles/2008/09/04/the-open-closed-principle-for-languages-with-open-classes#comment-2036</link>
    </item>
    <item>
      <title>"The Open-Closed Principle for Languages with Open Classes" by murphee</title>
      <description>&lt;p&gt;@PatMaddox:
&amp;#8220;and now we have to recompile every client of Dog.&amp;#8221;&lt;/p&gt;


	&lt;p&gt;No we don&amp;#8217;t. Try it.&lt;/p&gt;</description>
      <pubDate>Fri, 05 Sep 2008 16:23:00 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:546fcfe4-1570-4230-8276-9b48f2cb0a7c</guid>
      <link>http://blog.objectmentor.com/articles/2008/09/04/the-open-closed-principle-for-languages-with-open-classes#comment-2034</link>
    </item>
    <item>
      <title>"The Open-Closed Principle for Languages with Open Classes" by Pat Maddox</title>
      <description>&lt;p&gt;Ruby&amp;#8217;s dynamic nature allows you to make the kind of changes you proposed (adding a method) without violating OCP.  You can even modify the original source without violating OCP.  Consider the basic Ruby class:&lt;/p&gt;


	&lt;p&gt;class Dog
  def bark; &amp;#8220;woof!&amp;#8221; end
end&lt;/p&gt;


	&lt;p&gt;and its equivalent-ish Java class:&lt;/p&gt;


	&lt;p&gt;public class Dog {
  public String bark() { return &amp;#8220;woof!&amp;#8221;; }
}&lt;/p&gt;


	&lt;p&gt;Now we add another method to Ruby.Dog:&lt;/p&gt;


	&lt;p&gt;class Dog
  def bark; &amp;#8220;woof!&amp;#8221; end
  def snarl; &amp;#8220;gnashing of teeth&amp;#8221; end
end&lt;/p&gt;


	&lt;p&gt;and we go on with business as usual.&lt;/p&gt;


	&lt;p&gt;Now we add another method to Java.Dog:&lt;/p&gt;


	&lt;p&gt;public class Dog {
  public String bark() { return &amp;#8220;woof!&amp;#8221;; }
  public String snarl() { return &amp;#8220;gnashing of teeth&amp;#8221;; }
}&lt;/p&gt;


	&lt;p&gt;and now we have to &lt;strong&gt;recompile every client of Dog&lt;/strong&gt;.&lt;/p&gt;


	&lt;p&gt;To me, OCP is all about avoiding changes that screw up clients of a given class.  You can really screw them up by changing the implementation in such a way that violates the original contract, or you can simply cause a nuisance by forcing them to be recompiled.  In Ruby and other dynamic languages, you still have to think about the first part, but at least the second class of problems has gone away.&lt;/p&gt;</description>
      <pubDate>Fri, 05 Sep 2008 15:25:13 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:23c1bd32-95ab-4fb8-a63c-d507ba52c30d</guid>
      <link>http://blog.objectmentor.com/articles/2008/09/04/the-open-closed-principle-for-languages-with-open-classes#comment-2033</link>
    </item>
    <item>
      <title>"The Open-Closed Principle for Languages with Open Classes" by Michael Feathers</title>
      <description>&lt;p&gt;@Glenn I agree.  I keep thinking that there&amp;#8217;s a principle below all of this which is something like: Never write code that nullifies the behavior of existing code.&lt;/p&gt;


	&lt;p&gt;We should be able to understand the system from the sources.  If we see a method, we should know that its behavior is there in the system, and although people may add to that behavior in various ways, they won&amp;#8217;t nullify it through other code.&lt;/p&gt;</description>
      <pubDate>Fri, 05 Sep 2008 14:51:37 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:28e1a3f8-8691-43af-86b1-8e7654b47dc7</guid>
      <link>http://blog.objectmentor.com/articles/2008/09/04/the-open-closed-principle-for-languages-with-open-classes#comment-2032</link>
    </item>
    <item>
      <title>"The Open-Closed Principle for Languages with Open Classes" by Glenn Vanderburg</title>
      <description>&lt;p&gt;One of the guiding principles of dynamic languages like Ruby is that there should be rules, but nearly always with escape hatches.&lt;/p&gt;


	&lt;p&gt;I think open classes (or at least some uses of them) are definitely violations of OCP, in the same way that #instance_variable_get violates encapsulation.  That doesn&amp;#8217;t mean it&amp;#8217;s bad; it just means it&amp;#8217;s &lt;em&gt;worse&lt;/em&gt; than other alternatives.&lt;/p&gt;


	&lt;p&gt;Face it &amp;#8230; it&amp;#8217;s pretty hard to design a class that gets it exactly right with respect to OCP, and is extensible in all the right ways.  And we have to work with classes that aren&amp;#8217;t ideally designed.  In the face of that, those escape hatches are invaluable.&lt;/p&gt;


	&lt;p&gt;The danger, of course, is that when designing classes we will just rely on the escape hatches and not try to design our classes for extension.&lt;/p&gt;</description>
      <pubDate>Fri, 05 Sep 2008 14:33:09 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:ca454fc5-dd46-49dd-ba00-e3d09c5668ce</guid>
      <link>http://blog.objectmentor.com/articles/2008/09/04/the-open-closed-principle-for-languages-with-open-classes#comment-2031</link>
    </item>
    <item>
      <title>"The Open-Closed Principle for Languages with Open Classes" by Dean Wampler</title>
      <description>&lt;p&gt;Concerning &lt;em&gt;World Design Headquarters&lt;/em&gt;, I was of course inspired by the &lt;a href="http://www.thedailyshow.com/" rel="nofollow"&gt;Daily Show&lt;/a&gt; ;)&lt;/p&gt;


	&lt;p&gt;@Hugo, thanks. I&amp;#8217;m sure we can add more blogs on &amp;#8220;dynamic design&amp;#8221;!&lt;/p&gt;


	&lt;p&gt;Here&amp;#8217;s another perspective; what we really care about is &lt;em&gt;feature modularity&lt;/em&gt;. I&amp;#8217;d like to be able to reason about how a feature behaves (for any appropriate definition of &amp;#8220;feature&amp;#8221;). Think about OOP for a second; we allow the definition of a class to be spread over several &amp;#8220;physical artifacts&amp;#8221;, &lt;em&gt;i.e.&lt;/em&gt;, a base class + mixins/interfaces + subclasses, sometimes in separate files. If I want to reason about the behavior of a &lt;code&gt;FileInputStream&lt;/code&gt;, I have to look in several places, for example.&lt;/p&gt;


	&lt;p&gt;I remember when OOP went viral. Lots of C programmers complained that they couldn&amp;#8217;t figure out what their code was doing anymore, because the flow of control hoped around. With better tools (and drugs?) we got used to it.&lt;/p&gt;


	&lt;p&gt;The challenge of open classes is similar; we need modular reasoning over a set of artifacts. Tooling will help, so will programming conventions, practice, etc.&lt;/p&gt;


	&lt;p&gt;I agree to a point with Michael that I don&amp;#8217;t think Meyer intended OCP to be just a source thing. It really is a statement of the power of extension through inheritance. He probably didn&amp;#8217;t have open types in mind. (IIRC, Eiffel doesn&amp;#8217;t support them.) That&amp;#8217;s partly why I added the &amp;#8220;contract&amp;#8221; bit, so that our &amp;#8220;non-local&amp;#8221; extensions are done in a principled way.&lt;/p&gt;</description>
      <pubDate>Fri, 05 Sep 2008 14:10:21 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:ba42d51f-d580-41c3-9b58-b19e5439823e</guid>
      <link>http://blog.objectmentor.com/articles/2008/09/04/the-open-closed-principle-for-languages-with-open-classes#comment-2030</link>
    </item>
    <item>
      <title>"The Open-Closed Principle for Languages with Open Classes" by Michael Feathers</title>
      <description>&lt;p&gt;I have a couple of problems with seeing OCP as a source level thing.  The first is that if we do, OCP doesn&amp;#8217;t really offer much guidance.  In a language as dynamic as Ruby, you can replace anything you like without touching the original source.  If the source of a class can always remain closed (i.e., it doesn&amp;#8217;t have to change) we could legitimately say that dynamic languages give you OCP trivially so it&amp;#8217;s probably not worth talking about OCP at all.&lt;/p&gt;


	&lt;p&gt;The second problem I have with seeing OCP as a source level thing is that open classes present problems of their own that, ideally, OCP should say something about.  OCP adherence often triggers the creation of orthogonal abstractions: you split the class and then you know that mucking with one responsibility isn&amp;#8217;t going to muck with the other.  With open classes, you could easily make a change to a class in one file which accidentally clobbers functionality in another file.  In a behavioral sense, the original file was never really closed then, was it?  Other clients could be affected.&lt;/p&gt;


	&lt;p&gt;Languages which allow self-modifying code are a bit of a different animal than what Meyer was considering.&lt;/p&gt;</description>
      <pubDate>Fri, 05 Sep 2008 13:38:01 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:9a155f37-554d-4b3e-ae76-5a83810dfb25</guid>
      <link>http://blog.objectmentor.com/articles/2008/09/04/the-open-closed-principle-for-languages-with-open-classes#comment-2029</link>
    </item>
    <item>
      <title>"The Open-Closed Principle for Languages with Open Classes" by Hugo Bara&#250;na</title>
      <description>&lt;p&gt;Good post! =) I would like to see more posts about Object Oriented Design inside the dynamic languages world, mainly the Ruby world.&lt;/p&gt;</description>
      <pubDate>Fri, 05 Sep 2008 12:57:42 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:0e0572cc-cc94-4e01-b1b9-561e17fcb4df</guid>
      <link>http://blog.objectmentor.com/articles/2008/09/04/the-open-closed-principle-for-languages-with-open-classes#comment-2028</link>
    </item>
    <item>
      <title>"The Open-Closed Principle for Languages with Open Classes" by Ravi Venkataraman</title>
      <description>&lt;p&gt;I am impressed, too, with &amp;#8220;World Design Headquarters&amp;#8221;.&lt;/p&gt;


	&lt;p&gt;This creates the impression that there are several design locations around the world. It also suggests that there are other non-design locations, maybe a training headquarters, a development headquarters, a QA headquarters, etc.&lt;/p&gt;


	&lt;p&gt;Would not such divisions of software construction go against the Agile philosophy?&lt;/p&gt;</description>
      <pubDate>Fri, 05 Sep 2008 12:50:20 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:9e73abe5-d557-4be3-bf8f-e1289337b48e</guid>
      <link>http://blog.objectmentor.com/articles/2008/09/04/the-open-closed-principle-for-languages-with-open-classes#comment-2027</link>
    </item>
    <item>
      <title>"The Open-Closed Principle for Languages with Open Classes" by Brian Chiasson</title>
      <description>&lt;p&gt;@Micah,&lt;/p&gt;


	&lt;p&gt;That&amp;#8217;s an interesting spin on class definitions and would indeed be confusing. If we weren&amp;#8217;t talking Ruby, I would suggest defining two different interfaces for the Dog class that your clients can use and leave the two methods in the same class definition &amp;#8211; ILoudDog and IAggressiveDog.&lt;/p&gt;</description>
      <pubDate>Fri, 05 Sep 2008 12:04:57 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:eb87b507-9d5d-414a-a559-660a89959a58</guid>
      <link>http://blog.objectmentor.com/articles/2008/09/04/the-open-closed-principle-for-languages-with-open-classes#comment-2026</link>
    </item>
    <item>
      <title>"The Open-Closed Principle for Languages with Open Classes" by An impressed ...</title>
      <description>&lt;p&gt;&amp;#8220;Object Mentor World Design Headquarters.&amp;#8221;&lt;/p&gt;


	&lt;p&gt;WOOOAAAAHHH!!!&lt;/p&gt;</description>
      <pubDate>Fri, 05 Sep 2008 10:04:34 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:bfbe6840-0300-492f-83ee-6b2c08030739</guid>
      <link>http://blog.objectmentor.com/articles/2008/09/04/the-open-closed-principle-for-languages-with-open-classes#comment-2024</link>
    </item>
    <item>
      <title>"The Open-Closed Principle for Languages with Open Classes" by Micah Martin</title>
      <description>&lt;p&gt;I&amp;#8217;m still intrigued by the design implication of open classes.  I agree that opening classes does not necessarily violate OCP. But contrary to Dave Hoover&amp;#8217;s comment, I frequently want to reopen my own classes to avoid violating the ISP, Interface Segregation Principle.&lt;/p&gt;


	&lt;p&gt;For example, I have class Dog.  One client of Dog uses it to bark().  Another client uses Dog to bite().  The barking client doesn&amp;#8217;t care about biting and the biting client doesn&amp;#8217;t care about barking.  So in each client I&amp;#8217;ll open the Dog class and add the desired behavior.&lt;/p&gt;


	&lt;p&gt;But I wonder&amp;#8230;. is this bad design?  Reading the code becomes more challenging since the behavior of Dog is in many locations.&lt;/p&gt;</description>
      <pubDate>Fri, 05 Sep 2008 03:01:28 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:ea3f714f-d113-46fb-8c35-21799360ae71</guid>
      <link>http://blog.objectmentor.com/articles/2008/09/04/the-open-closed-principle-for-languages-with-open-classes#comment-2023</link>
    </item>
    <item>
      <title>"The Open-Closed Principle for Languages with Open Classes" by Dave Hoover</title>
      <description>&lt;p&gt;I wouldn&amp;#8217;t say it&amp;#8217;s normal in Ruby to define a class in foo.rb and then re-open it in foo2.rb later.  It&amp;#8217;s certainly possible, but it&amp;#8217;s more common to re-open &lt;strong&gt;someone else&amp;#8217;s&lt;/strong&gt; class, such as String.  If you own the class, then the normal thing to do is just edit the source, or if you want to adhere to OCP, then sub-class or decorate.&lt;/p&gt;</description>
      <pubDate>Thu, 04 Sep 2008 22:28:49 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:ffdc2049-cba4-4c76-a22b-d8c062d285fe</guid>
      <link>http://blog.objectmentor.com/articles/2008/09/04/the-open-closed-principle-for-languages-with-open-classes#comment-2022</link>
    </item>
  </channel>
</rss>
