<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Jeff M on Medium]]></title>
        <description><![CDATA[Stories by Jeff M on Medium]]></description>
        <link>https://medium.com/@jeffm712?source=rss-1a2b2fcd4e2d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*VeO1VLl5C981WDeA.jpg</url>
            <title>Stories by Jeff M on Medium</title>
            <link>https://medium.com/@jeffm712?source=rss-1a2b2fcd4e2d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 15 Nov 2026 13:23:31 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jeffm712/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[What is a class, anyway?]]></title>
            <link>https://medium.com/@jeffm712/what-is-a-class-anyway-89f7570340a9?source=rss-1a2b2fcd4e2d------2</link>
            <guid isPermaLink="false">https://medium.com/p/89f7570340a9</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Jeff M]]></dc:creator>
            <pubDate>Fri, 06 Nov 2015 00:26:59 GMT</pubDate>
            <atom:updated>2015-11-06T00:43:08.516Z</atom:updated>
            <content:encoded><![CDATA[<p>We in the JavaScript community tend to have a very narrow view of what a class is and of what classical inheritance can do. We tend to think that classical inheritance can only be a compile-time, single-parent relationship. But what if I told you that classes and classical inheritance are much more versatile than you may have thought?</p><ul><li>A class can be either a compile-time concept (such as in Java or C#) or a class can be a run-time object (such as in Python or Smalltalk).</li><li>The inheritance <em>process</em> can happen either at compile-time (such as in Java or C++) or the inheritance process can happen at run-time (such as in Python or JavaScript).</li><li>A descendant can either be limited to inherit from just one parent (such as in C# or JavaScript) or a descendant may be allowed to inherit from any number of parents (such as in C++ or Python).</li></ul><p>So what, then, ties it all together? What is a class? What is inheritance? (From the UML manual) A class is the description of both <strong>the data structure and the behavior that is shared among a set of objects</strong>. And inheritance is the process of <strong>incorporating structure and behavior</strong>.</p><p>Consider this Python code:</p><pre>class B():<br> def b(self):<br>  return &quot;b&quot;</pre><pre>class D(B):<br> def d(self):<br>  return &quot;d&quot;</pre><pre>instance = D()<br>instance.b() # &quot;b&quot;<br>instance.d() # &quot;d&quot;</pre><p>Are these classes? Is this classical inheritance?</p><p>What if I told you that <em>class B</em> and <em>class D</em> are themselves runtime objects? What if I told you that when we access <em>instance.b</em>, Python looks for the name “b” on the instance object, and if it doesn’t find it, then it looks for it on the “D” object, and if it still doesn’t find it, it looks on the “B” object, and so on down the inheritance chain.</p><p>Does that process sound familiar?</p><p>Next, consider these JavaScript factory functions:</p><pre>function b() {<br> return {<br>  b: function () {<br>   return &#39;b&#39;;<br>  },<br> };<br>}</pre><pre>function d() {<br> return Object.assign(b(), {<br>  d: function () {<br>   return &#39;d&#39;;<br>  },<br> });<br>}</pre><pre>var o = d()<br>o.b(); // &quot;b&quot;<br>o.d(); // &quot;d&quot;</pre><p>We may be reluctant to call these classes or classical inheritance, but here’s what we can certainly say:</p><p>“d” defines a structure and behavior that is common to a set of objects, and it incorporates the structure and behavior of “b”, which itself defines a structure and behavior that is common to a set of objects.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=89f7570340a9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Composition vs Inheritance]]></title>
            <link>https://medium.com/@jeffm712/composition-vs-inheritance-bfa91c996160?source=rss-1a2b2fcd4e2d------2</link>
            <guid isPermaLink="false">https://medium.com/p/bfa91c996160</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Jeff M]]></dc:creator>
            <pubDate>Tue, 03 Nov 2015 20:42:43 GMT</pubDate>
            <atom:updated>2015-11-03T20:42:43.711Z</atom:updated>
            <content:encoded><![CDATA[<p>Mirroring <a href="https://www.reddit.com/r/javascript/comments/3r50dk/es6_composition_vs_inheritance/cwl9u2g">a reddit post of mine</a> to here.</p><p>* * * *</p><p>The first thing we need to do is clear up definitions. This topic has become muddied recently. Both “inheritance” and “composition” have very specific and technical definitions, but a popular blogger has invented his own definitions, ones that are very broad and generic and not compatible with the industry standard.</p><p>The industry standard definition of “inheritance” (from the UML manual) is “incorporating structure and behavior.” That could take the form of a class extending another class, or an object delegating to another object, or copying properties into another object. Any of these bring about the same result: incorporating structure and behavior.</p><p>The industry standard definition of “composition” is “acquiring references to objects.” That is, one object would have a property whose value is a reference to another object.</p><p>Given those definitions, composition (acquiring references) is preferred because:</p><ul><li>When you inherit, you typically get access to the base’s internal implementation.</li><li>When you compose, you interact only with the object’s public interface.</li><li>When you inherit, their interface becomes your interface. Client code will come to depend on that, which makes it hard to change your inheritance decision later on.</li><li>When you compose, the private reference is under your control. You decide what interface you want to expose.</li><li>When you inherit, it’s hard to change what you inherit from at runtime (varies by language; JavaScript actually makes this easy).</li><li>When you compose, it’s easy to reassign a different object reference.</li><li>When you inherit, you might be limited to only a single parent (varies by language; JavaScript’s prototype chain is limited to only a single parent).</li><li>When you compose, you can hold references to any number of objects.</li></ul><p>As a rule of thumb, use inheritance only when you want polymorphic behavior. “The purpose of inheritance is <strong>not</strong> for the derived to reuse the base’s code. The purpose of inheritance is to implement substitutability.”</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bfa91c996160" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>