<?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>foilhat.org &#187; perl</title>
	<atom:link href="http://foilhat.org/category/perl/feed/" rel="self" type="application/rss+xml" />
	<link>http://foilhat.org</link>
	<description>put on your tinfoil hat.</description>
	<lastBuildDate>Tue, 01 Dec 2009 20:04:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Deep Polymorphism in Perl</title>
		<link>http://foilhat.org/2008/09/23/deep-polymorphism-in-perl/</link>
		<comments>http://foilhat.org/2008/09/23/deep-polymorphism-in-perl/#comments</comments>
		<pubDate>Tue, 23 Sep 2008 15:07:04 +0000</pubDate>
		<dc:creator>kitchen</dc:creator>
				<category><![CDATA[perl]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[polymorphism]]></category>
		<category><![CDATA[work]]></category>

		<guid isPermaLink="false">http://foilhat.org/?p=18</guid>
		<description><![CDATA[While writing some code for work and exploring our class layout, I&#8217;ve already implemented some polymorphism.  For instance, if you pull up an object for a service, it goes ahead and gives you the appropriate class for that service.  All you have to do is instantiate the service object, you don&#8217;t need to care about [...]]]></description>
			<content:encoded><![CDATA[<p>While writing some code for work and exploring our class layout, I&#8217;ve already implemented some polymorphism.  For instance, if you pull up an object for a service, it goes ahead and gives you the appropriate class for that service.  All you have to do is instantiate the service object, you don&#8217;t need to care about the class.  This is very elementary stuff, and works very well.</p>
<p>However, I&#8217;d like to take that a step further and go ahead and do multiple levels of polymorphism.  We also currently have polymorphism on our DomainService objects, which define types of services provided with a domain (mail, dns, http, https, jabber, etc).  As you may have just noticed, there&#8217;s already a place for some deeper polymorphism there, as the http and https domain service types will generally share quite a lot of code.  We&#8217;re currently using a method similar to <a title="It's a dog, but what kind? [perlmonks.org]" href="http://www.perlmonks.org/?node_id=339131">this article on perlmonks</a> to achieve our one-level of polymorphism, but I&#8217;m not so sure I want to have to hack up the base class every time I want to add another level of polymorphism (not saying that it will happen often, but it shouldn&#8217;t be necessary).</p>
<p>I&#8217;m currently investigating options, but if anyone has done this, I would love to see some examples!  And of course, I will share examples if I figure it out on my own <img src='http://foilhat.org/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>Update: Well, I feel a bit silly for making this post when the solution was so easy.  The problem was more that I was thinking about the wrong approach.</p>
<p>Currently we have some classes like this:</p>
<ul>
<li>DomainService</li>
<li>DomainService::Http</li>
<li>DomainService::Https</li>
<li>DomainService::Dns</li>
</ul>
<p>We instantiate DomainService and it polymorphs into the lower types.  Currently everything is up in the Domain object and the polymorph modules are empty stubs, but with refactoring this will change.  However, I didn&#8217;t want to duplicate code between the Http and Https types, considering they&#8217;re almost entirely identical, so I was thinking of having DomainService polymorph into DomainService::Http which would polymorph into DomainService::Http::Http and DomainService::Http::Https.  However, I came to my senses and realized that&#8217;s not the correct approach.  The correct approach is to do something like this:</p>
<ul>
<li>DomainService</li>
<li>DomainService::HttpBase</li>
<li>DomainService::Http</li>
<li>DomainService::Https</li>
</ul>
<p>Where DomainService::Http and DomainService::Https are subclasses of DomainService::HttpBase which is itself a subclass of DomainService.  So, Domain polymorphs into DomainService::Http and magically inherits the DomainService::HttpBase class.  Duh.</p>
<p>Leaving this here for posterity if nothing else <img src='http://foilhat.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://foilhat.org/2008/09/23/deep-polymorphism-in-perl/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
