<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Shawson&#039;s Code Blog &#187; OO Design</title>
	<atom:link href="http://www.shawson.co.uk/codeblog/category/oo-design/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.shawson.co.uk/codeblog</link>
	<description>development notes for my failing memory</description>
	<lastBuildDate>Mon, 26 Jul 2010 19:08:45 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>OO &amp; Inheritance with Javascript</title>
		<link>http://www.shawson.co.uk/codeblog/oo-inheritance-with-javascript/</link>
		<comments>http://www.shawson.co.uk/codeblog/oo-inheritance-with-javascript/#comments</comments>
		<pubDate>Sun, 23 May 2010 18:02:22 +0000</pubDate>
		<dc:creator>shawson</dc:creator>
				<category><![CDATA[OO Design]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.shawson.co.uk/codeblog/?p=551</guid>
		<description><![CDATA[I&#8217;m getting ready to start a game development project and getting my OO Javascript up to scratch- I&#8217;ve been googling around for a while as there seems to be a whole load of different ways to implement OO and in particular inheritance in javascript.  I&#8217;ve finally found a method that work&#8217;s reliably, and with multiple [...]


Related posts:<ul><li><a href='http://www.shawson.co.uk/codeblog/creating-a-re-usable-shopping-basket-with-generics-in-c-sharp/' rel='bookmark' title='Permanent Link: Creating a re-usable shopping basket with Generics in C#'>Creating a re-usable shopping basket with Generics in C#</a></li>
<li><a href='http://www.shawson.co.uk/codeblog/html5-audio-and-video-media-tags-how-do-you-know-when-the-datas-loaded-and-how-to-play-multiple-instances-of-the-same-sample-at-the-same-time/' rel='bookmark' title='Permanent Link: HTML5 Audio and Video (Media) Tags &#8211; How do you know when the data&#8217;s loaded? And how to play multiple instances of the same sample at the same time'>HTML5 Audio and Video (Media) Tags &#8211; How do you know when the data&#8217;s loaded? And how to play multiple instances of the same sample at the same time</a></li>
<li><a href='http://www.shawson.co.uk/codeblog/google-code-highlighter/' rel='bookmark' title='Permanent Link: Google Code Highlighter'>Google Code Highlighter</a></li>
</ul>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m getting ready to start a game development project and getting my OO Javascript up to scratch- I&#8217;ve been googling around for a while as there seems to be a whole load of different ways to implement OO and in particular inheritance in javascript.  I&#8217;ve finally found a method that work&#8217;s reliably, and with multiple generation of inheritance- It&#8217;s from an <a href="http://www.sitepoint.com/blogs/2006/01/17/javascript-inheritance/">article on the site point website</a> &#8211; for quick reference I will cut to the meat and give a usage example- for details see the original article;</p>
<p>add this function to your project;</p>
<pre>
<pre class="brush: javascript">
function copyPrototype(descendant, parent) {
  var sConstructor = parent.toString();
  var aMatch = sConstructor.match( /\s*function (.*)\(/ );
  if ( aMatch != null ) { descendant.prototype[aMatch[1]] = parent; }
  for (var m in parent.prototype) {
    descendant.prototype[m] = parent.prototype[m];
  }
};
</pre>
</pre>
<p>Then define your classes (prototypes) like so;</p>
<pre>
<pre class="brush: javascript">
function AClass(param) {
   this.Text=param;
}
AClass.prototype.Speak = function() {
  alert(this.Text);
}

function BClass(param, name) {
  this.AClass(param);
  this.Name = name;
}
copyPrototype(BClass, AClass);
BClass.prototype.Speak = function() {
  alert(&#039;Hi &#039; + name);

  // Call overridden parent method...
  AClass.prototype.Speak.apply(this);
}
</pre>
</pre>
<p>So the above example will give you 2 classes- B is derived from A.  Calling AClass.Speak will give you a single alert with the contents of the &#8216;text&#8217; property, whereas BClass.Speak will give you two text boxes; the first greeting you by name, and the second being the alert box from AClass.  I&#8217;ve tested this myself with multiple generations of inheritance and it worked fine, where <a href="http://www.coolpage.com/developer/javascript/Correct%20OOP%20for%20Javascript.html">other</a> <a href="http://phrogz.net/JS/Classes/OOPinJS2.html">methods</a> have not.</p>


<p>Related posts:<ul><li><a href='http://www.shawson.co.uk/codeblog/creating-a-re-usable-shopping-basket-with-generics-in-c-sharp/' rel='bookmark' title='Permanent Link: Creating a re-usable shopping basket with Generics in C#'>Creating a re-usable shopping basket with Generics in C#</a></li>
<li><a href='http://www.shawson.co.uk/codeblog/html5-audio-and-video-media-tags-how-do-you-know-when-the-datas-loaded-and-how-to-play-multiple-instances-of-the-same-sample-at-the-same-time/' rel='bookmark' title='Permanent Link: HTML5 Audio and Video (Media) Tags &#8211; How do you know when the data&#8217;s loaded? And how to play multiple instances of the same sample at the same time'>HTML5 Audio and Video (Media) Tags &#8211; How do you know when the data&#8217;s loaded? And how to play multiple instances of the same sample at the same time</a></li>
<li><a href='http://www.shawson.co.uk/codeblog/google-code-highlighter/' rel='bookmark' title='Permanent Link: Google Code Highlighter'>Google Code Highlighter</a></li>
</ul></p>]]></content:encoded>
			<wfw:commentRss>http://www.shawson.co.uk/codeblog/oo-inheritance-with-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Thycotic Design Pattern Articles</title>
		<link>http://www.shawson.co.uk/codeblog/thycotic-pattern-articles/</link>
		<comments>http://www.shawson.co.uk/codeblog/thycotic-pattern-articles/#comments</comments>
		<pubDate>Fri, 31 Jul 2009 14:16:37 +0000</pubDate>
		<dc:creator>shawson</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[C#.net]]></category>
		<category><![CDATA[OO Design]]></category>

		<guid isPermaLink="false">http://www.shawson.co.uk/codeblog/?p=320</guid>
		<description><![CDATA[Great bunch of articles on different design patterns up on the Thycotic Blog;

The Strategy Pattern
The Template Pattern



Related posts:Google Code Highlighter
Missing / Corrupt *.aspx(/ascx).Designer.cs file
Some handy Regular Expressions



Related posts:<ul><li><a href='http://www.shawson.co.uk/codeblog/google-code-highlighter/' rel='bookmark' title='Permanent Link: Google Code Highlighter'>Google Code Highlighter</a></li>
<li><a href='http://www.shawson.co.uk/codeblog/missing-corrupt-aspxascx-designer-cs-file/' rel='bookmark' title='Permanent Link: Missing / Corrupt *.aspx(/ascx).Designer.cs file'>Missing / Corrupt *.aspx(/ascx).Designer.cs file</a></li>
<li><a href='http://www.shawson.co.uk/codeblog/some-handy-regular-expressions/' rel='bookmark' title='Permanent Link: Some handy Regular Expressions'>Some handy Regular Expressions</a></li>
</ul>]]></description>
			<content:encoded><![CDATA[<p>Great bunch of articles on different design patterns up on the Thycotic Blog;</p>
<ul>
<li><a href="http://www.thycotic.com/bringing-plausible-deniability-to-development-the-strategy-pattern" target="_blank">The Strategy Pattern</a></li>
<li><a href="http://www.thycotic.com/the-template-pattern-a-benevolent-dictator" target="_blank">The Template Pattern</a></li>
</ul>


<p>Related posts:<ul><li><a href='http://www.shawson.co.uk/codeblog/google-code-highlighter/' rel='bookmark' title='Permanent Link: Google Code Highlighter'>Google Code Highlighter</a></li>
<li><a href='http://www.shawson.co.uk/codeblog/missing-corrupt-aspxascx-designer-cs-file/' rel='bookmark' title='Permanent Link: Missing / Corrupt *.aspx(/ascx).Designer.cs file'>Missing / Corrupt *.aspx(/ascx).Designer.cs file</a></li>
<li><a href='http://www.shawson.co.uk/codeblog/some-handy-regular-expressions/' rel='bookmark' title='Permanent Link: Some handy Regular Expressions'>Some handy Regular Expressions</a></li>
</ul></p>]]></content:encoded>
			<wfw:commentRss>http://www.shawson.co.uk/codeblog/thycotic-pattern-articles/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating a re-usable shopping basket with Generics in C#</title>
		<link>http://www.shawson.co.uk/codeblog/creating-a-re-usable-shopping-basket-with-generics-in-c-sharp/</link>
		<comments>http://www.shawson.co.uk/codeblog/creating-a-re-usable-shopping-basket-with-generics-in-c-sharp/#comments</comments>
		<pubDate>Wed, 15 Apr 2009 15:55:20 +0000</pubDate>
		<dc:creator>shawson</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[C#.net]]></category>
		<category><![CDATA[OO Design]]></category>

		<guid isPermaLink="false">http://www.shawson.co.uk/codeblog/?p=121</guid>
		<description><![CDATA[We recently had troubles with our new reusable basket we&#8217;re developing at work.  We sell books, and most books come from one central data source which for the sake of this article i shall call CDS- so we have a CDS entities project which holds elements Group, Book, Author etc.  However not all of our [...]


Related posts:<ul><li><a href='http://www.shawson.co.uk/codeblog/syndicating-to-rss-using-the-build-in-net-syndicationfeed-classes/' rel='bookmark' title='Permanent Link: Syndicating to RSS using the built in .net SyndicationFeed classes'>Syndicating to RSS using the built in .net SyndicationFeed classes</a></li>
<li><a href='http://www.shawson.co.uk/codeblog/asp-net-aspx-pages-posting-back-to-the-wrong-url-when-using-server-rewrite/' rel='bookmark' title='Permanent Link: ASP.net aspx pages posting back to the wrong URL when using Server Rewrite'>ASP.net aspx pages posting back to the wrong URL when using Server Rewrite</a></li>
<li><a href='http://www.shawson.co.uk/codeblog/linq-distinct/' rel='bookmark' title='Permanent Link: Linq Distinct!'>Linq Distinct!</a></li>
</ul>]]></description>
			<content:encoded><![CDATA[<p>We recently had troubles with our new reusable basket we&#8217;re developing at work.  We sell books, and most books come from one <strong>c</strong>entral <strong>d</strong>ata <strong>s</strong>ource which for the sake of this article i shall call CDS- so we have a CDS entities project which holds elements Group, Book, Author etc.  However not all of our sites run use the CDS for their data- so we have other projects with their own elements for Book, Author, Category etc which hold their own data.</p>
<p>We wanted to create a central project containing the basket functionality which we could drop into any project and use.  So the basket needs to be able to add lots of different types of books- some from the CDS entity library or some any other entity library we use.  To do this we created an Interfaces project which holds an interface called IBook which held the minimum data required by the basket such as Title, Price, ISBN, Cover Image.  This project is then referenced by the sites, the entity libraries (like CDS or any other&#8217;s we build) and the basket itself.</p>
<p>Adding the book to the basket was fine, however the problem arose when viewing items- the basket needed to be able to load the book data back- this is fine we thought- we would simply add a load() method to IBook, however this didnt solve the problem as the basket only had IBook signature of load- it didn&#8217;t know which concrete implementation of load to run.</p>
<p>The answer was to use generics.  We added a generic parameter to the top of the basket which accepted a type which it assumed to be derived from IBook and always have a default constructor, like so;</p>
<pre class="brush: c-sharp">
public class Basket&lt;T&gt; where T : Hachette.ProcessLayer.IBook, new() {
   private List&lt;BasketItem&lt;T&gt;&gt; _basket_items;
   ...
}
</pre>
<p>
Likewise we made the basket item&#8217;s generic, and pass the type T from the basket to the basket item when instanciating them- the basket items are then able to define a real book instance of type T so it knows which concrete book it&#8217;s dealing with, so it can call the correct load method.  The use of generics here means the basket object can reference a real book class from the CDS project (in a separate assembly) without having to reference that assembly, meaning we can drop in any type of book from any assembly for future sites, and with the parent website stating the type to use when creating the basket, the basket can remain completely independent.</p>


<p>Related posts:<ul><li><a href='http://www.shawson.co.uk/codeblog/syndicating-to-rss-using-the-build-in-net-syndicationfeed-classes/' rel='bookmark' title='Permanent Link: Syndicating to RSS using the built in .net SyndicationFeed classes'>Syndicating to RSS using the built in .net SyndicationFeed classes</a></li>
<li><a href='http://www.shawson.co.uk/codeblog/asp-net-aspx-pages-posting-back-to-the-wrong-url-when-using-server-rewrite/' rel='bookmark' title='Permanent Link: ASP.net aspx pages posting back to the wrong URL when using Server Rewrite'>ASP.net aspx pages posting back to the wrong URL when using Server Rewrite</a></li>
<li><a href='http://www.shawson.co.uk/codeblog/linq-distinct/' rel='bookmark' title='Permanent Link: Linq Distinct!'>Linq Distinct!</a></li>
</ul></p>]]></content:encoded>
			<wfw:commentRss>http://www.shawson.co.uk/codeblog/creating-a-re-usable-shopping-basket-with-generics-in-c-sharp/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
