<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" 
      xmlns:thr="http://purl.org/syndication/thread/1.0">
  <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/12/why-use-base-classes.html" />
  <link rel="self" type="application/atom+xml" href="http://www.insideria.com/atom.xml" />
  <id>tag:www.insideria.com,2009://34/tag:www.insideria.com,2008://34.34749-</id>
  <updated>2009-11-19T15:01:07Z</updated>
  <title>Comments for Why use base classes? (http://www.insideria.com/2008/12/why-use-base-classes.html)</title>
  <generator uri="http://www.sixapart.com/movabletype/">Movable Type 4.21-en</generator>
  <entry>
    <id>tag:www.insideria.com,2008://34.34749</id>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/12/why-use-base-classes.html" />
    <link rel="service.edit" type="application/atom+xml" href="http://blogs.oreilly.com/cgi-bin/mt/mt-atom.cgi/weblog/blog_id=34/entry_id=34749" title="Why use base classes?" />
    <published>2008-12-23T03:04:37Z</published>
    <updated>2008-12-23T03:04:37Z</updated>
    <title>Why use base classes?</title>
    <summary>I was recently asked what was the point of using base classes for creating custom components, instead of just putting everything in a single class instance?  Well, there are several reasons that this is beneficial.  Here are just a few.</summary>
    <author>
      <name>Andrew Trice</name>
      
    </author>
    
    <category term="Blogs" />
    
    <content type="html" xml:lang="en" xml:base="http://www.insideria.com/">
      <![CDATA[<p>I was recently asked what was the point of using base classes for creating custom components, instead of just putting everything in a single class instance?  Well, there are several reasons that this is beneficial.  Here are just a few.</p>

<p><strong>Code Reuse</strong><br />
One of the main reasons to use inheritance (extending a base class) is for reusing code in various child classes.   If you have a subset of classes, and all of them would share a particular code segment, then there is no need to duplicate that segment of code for every class instance.   This would lead to multiple  versions of the exact same code which would have to be maintained for different component instances.  Creating a base class that encapsulates common logic saves you time.</p>

<p><strong>Code Simplicity</strong><br />
Abstracting complex logic in base classes can allow you to keep your higher-level components clean and easy to understand.   Rather than having a single component with multitudes of code to wrap your head around, you can have multiple classes with clearly defined code segments.   This is purely for code readability and maintainability.</p>

<p><strong>Code Flexibility</strong><br />
Equally as important as reuse and simplicity is flexibility of your code.   Let's say you have two components that are very similar, however they have two very distinct behaviors.   A base class could encapsulate all of the common logic, and in the child classes override logic in the base class for their own custom purposes.   Or, let's say you want to change the behavior of an existing component; You can simply override functions to make the existing component behave in a new manner.   </p>

<p>A simple example of this could be overriding a container to have a circular layout instead of a linear layout, or it could be overriding a mouse handler to perform a different function than the base component.</p>

<p><strong>Maintenance</strong><br />
Code that is simple, flexible, and reusable is typically easier to maintain... isn't that what we all want?</p>

<p>These are just a few reasons, but they should definitely be kept in mind when building your own applications.<br />
  <br />
___________________________________<br />
<strong>Andrew Trice</strong><br />
Principal Architect<br />
<a href="http://www.cynergysystems.com" target="_blank">Cynergy Systems<br />
http://www.cynergysystems.com</a></p>]]>
      
    </content>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2008://34.34749-comment:2049447</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2008://34.34749" type="text/html" href="http://www.insideria.com/2008/12/why-use-base-classes.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/12/why-use-base-classes.html#comment-2049447" />
    <title>Comment from Chris Brind on 2008-12-23</title>
    <author>
        <name>Chris Brind</name>
        <uri>http://www.perplentropy.com</uri>
    </author>
    <content type="html" xml:lang="en" xml:base="http://www.perplentropy.com">
        <![CDATA[<p>Need to be careful with posts like this.  It is reads as if you're saying that inheritance is the be all and end all.  It would be good if you would clarify the scenarios in which you might use this approach, rather than composition for example.</p>

<p>For instance, you should not use inheritance to build a complex UI - you should compose the UI of components, which in turn may be compositions of other components.  However, the lower level/more granular you get, it will become apparent that the shift from composition moves to inheritance.</p>

<p>All systems should be a careful balance of inheritance and composition, and this applies equally in the RIA space.</p>]]>
    </content>
    <published>2008-12-23T12:10:22Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2008://34.34749-comment:2049473</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2008://34.34749" type="text/html" href="http://www.insideria.com/2008/12/why-use-base-classes.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/12/why-use-base-classes.html#comment-2049473" />
    <title>Comment from Adnan Doric on 2008-12-23</title>
    <author>
        <name>Adnan Doric</name>
        <uri></uri>
    </author>
    <content type="html" xml:lang="en" xml:base="">
        <![CDATA[<p>I Think that composition is overall more suitable then inheritance.</p>

<p>Code Reuse<br />
Using inheritance, all of your child classes get ALL base code, so you always reuse all of the code, not something I'd call "reusable" in different contexts.</p>

<p>Code Simplicity<br />
I agree, inheritance is definitively simple, but in some cases composition can be simpler.</p>

<p>Code Flexibility<br />
You can't consider inheritance as "flexible" knowing that every change in your base class can break anything down the road. You are talking about encapsulation but basically, inheritance usually breaks encapsulation :)</p>

<p>Maintenance<br />
In the last part, you assume that the inherited code is "simple, flexible, and reusable" thus maintainable, sorry, it is maybe simple, but definitely not flexible or reusable except in very specific cases as Chris said.</p>]]>
    </content>
    <published>2008-12-23T18:00:12Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2008://34.34749-comment:2069809</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2008://34.34749" type="text/html" href="http://www.insideria.com/2008/12/why-use-base-classes.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2008/12/why-use-base-classes.html#comment-2069809" />
    <title>Comment from kokikono on 2009-08-05</title>
    <author>
        <name>kokikono</name>
        <uri>http://sevenato.com</uri>
    </author>
    <content type="html" xml:lang="en" xml:base="http://sevenato.com">
        <![CDATA[<p>Thanks Andrew Trice!</p>

<p>It is usefull for may my job.</p>

<p>I wish you have more..</p>]]>
    </content>
    <published>2009-08-05T11:12:31Z</published>
  </entry>

</feed
