<?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>Programmer&#039;s Notes &#187; adapter</title>
	<atom:link href="http://programmersnotes.info/tag/adapter/feed/" rel="self" type="application/rss+xml" />
	<link>http://programmersnotes.info</link>
	<description>Notes on the web-development and artificial intelligence.</description>
	<lastBuildDate>Mon, 18 Jul 2011 13:20:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>Difference between Adapter and Template Method pattern</title>
		<link>http://programmersnotes.info/2009/03/03/difference-between-adapter-and-template-method-pattern/</link>
		<comments>http://programmersnotes.info/2009/03/03/difference-between-adapter-and-template-method-pattern/#comments</comments>
		<pubDate>Tue, 03 Mar 2009 07:19:31 +0000</pubDate>
		<dc:creator>Konstantin Mirin</dc:creator>
				<category><![CDATA[Design patterns]]></category>
		<category><![CDATA[adapter]]></category>
		<category><![CDATA[design pattern]]></category>
		<category><![CDATA[OOP]]></category>
		<category><![CDATA[template method]]></category>
		<category><![CDATA[UML]]></category>

		<guid isPermaLink="false">http://programmersnotes.info/?p=99</guid>
		<description><![CDATA[The difference between Adapter and Template Method pattern


No related posts.

Related posts brought to you by <a href='http://yarpp.org'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>When I was studying patterns, I went through main patterns in the alphabetical order. Adapter pattern was in the beginning and Template Method &#8211; in the end. And when I came to the latter and read about it, I was confused. Thee solve the same task, implement the same GRASP principle (Protected Variations) &#8211; they are the same, but why are they called differently?<br />
<span id="more-99"></span><br />
But when I studied them both in more details, it turned out, that there is a significant difference between them. Yes, they solve the same things, but do this differently. To see this, take a look at UML&#8217;s:<br />
<div id="attachment_104" class="wp-caption aligncenter" style="width: 310px"><a href="http://programmersnotes.info/wp-content/uploads/2009/03/adapter1.png"><img src="http://programmersnotes.info/wp-content/uploads/2009/03/adapter-300x191.png" alt="Adapter design pattern" title="Adapter design pattern" width="300" height="191" class="size-medium wp-image-104" /></a><p class="wp-caption-text">Adapter design pattern</p></div><br />
Client calls the <strong>doRoutine()</strong> method of the correspondent adapter. And this adapter calls the specific method of each <strong>Adaptee</strong>. <strong>Adaptee</strong> may be some concrete class or some specific API or anything like this.</p>
<p><div id="attachment_106" class="wp-caption aligncenter" style="width: 310px"><a href="http://programmersnotes.info/wp-content/uploads/2009/03/templatemethod1.png"><img src="http://programmersnotes.info/wp-content/uploads/2009/03/templatemethod-300x206.png" alt="Template Method" title="Template Method" width="300" height="206" class="size-medium wp-image-106" /></a><p class="wp-caption-text">Template Method</p></div><br />
<strong>TemplateMethod()</strong> simply calls operations, that are different from class to class. Derived classes implement these operations (<strong>operation1()</strong>, <strong>operation2()</strong>&#8230;) and, as a result, we get working class with the functionality we need.</p>
<p>You see, using adapter is more like implementing the interface, while using Template Method is about implementing the parts of algorithm differently. So Adapter is used when we need all modules/components to response to the same API. At the same time, we use Template Method when we have some general process, which differs in minor details, which we implement in the derived classes.</p>
<p>For example, we should use Adapter pattern for the DB abstraction layer and TemplateMethod pattern for the calculation of table&#8217;s volume (see <a href="http://programmersnotes.info/2009/02/28/what-is-oop-object-oriented-programming/#improvements">&#8220;What is OOP post&#8221;</a>, I showed this example there)</p>
<h4>Further reading</h4>
<ul>
<li><a target="_blank" href="http://en.wikipedia.org/wiki/Adapter_pattern">Adapter pattern</a></li>
<li><a target="_blank" href="http://en.wikipedia.org/wiki/Template_method_pattern">Template Method pattern</a></li>
</ul>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a title="Click me to see the sites." href="#" onclick="$$('div.d99').each( function(e) { e.visualEffect('slide_down',{duration:2.5}) }); return false;"><strong><em>Liked the post? Bookmark it</em></strong></a>
<br />
<div class="d99" style="overflow:hidden">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http%3A%2F%2Fprogrammersnotes.info%2F2009%2F03%2F03%2Fdifference-between-adapter-and-template-method-pattern%2F&amp;title=Difference+between+Adapter+and+Template+Method+pattern" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://programmersnotes.info/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fprogrammersnotes.info%2F2009%2F03%2F03%2Fdifference-between-adapter-and-template-method-pattern%2F&amp;title=Difference+between+Adapter+and+Template+Method+pattern" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://programmersnotes.info/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http%3A%2F%2Fprogrammersnotes.info%2F2009%2F03%2F03%2Fdifference-between-adapter-and-template-method-pattern%2F" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://programmersnotes.info/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fprogrammersnotes.info%2F2009%2F03%2F03%2Fdifference-between-adapter-and-template-method-pattern%2F&amp;title=Difference+between+Adapter+and+Template+Method+pattern" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://programmersnotes.info/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http%3A%2F%2Fprogrammersnotes.info%2F2009%2F03%2F03%2Fdifference-between-adapter-and-template-method-pattern%2F&amp;T=Difference+between+Adapter+and+Template+Method+pattern" rel="nofollow" title="Add to&nbsp;Netscape"><img class="social_img" src="http://programmersnotes.info/wp-content/plugins/social-bookmarks/images/netscape.png" title="Add to&nbsp;Netscape" alt="Add to&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://slashdot.org/bookmark.pl?url=http%3A%2F%2Fprogrammersnotes.info%2F2009%2F03%2F03%2Fdifference-between-adapter-and-template-method-pattern%2F&amp;title=Difference+between+Adapter+and+Template+Method+pattern" rel="nofollow" title="Add to&nbsp;Slashdot"><img class="social_img" src="http://programmersnotes.info/wp-content/plugins/social-bookmarks/images/slashdot.png" title="Add to&nbsp;Slashdot" alt="Add to&nbsp;Slashdot" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fprogrammersnotes.info%2F2009%2F03%2F03%2Fdifference-between-adapter-and-template-method-pattern%2F&amp;title=Difference+between+Adapter+and+Template+Method+pattern" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://programmersnotes.info/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http%3A%2F%2Fprogrammersnotes.info%2F2009%2F03%2F03%2Fdifference-between-adapter-and-template-method-pattern%2F" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://programmersnotes.info/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+Difference+between+Adapter+and+Template+Method+pattern+@+http%3A%2F%2Fprogrammersnotes.info%2F2009%2F03%2F03%2Fdifference-between-adapter-and-template-method-pattern%2F" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://programmersnotes.info/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http%3A%2F%2Fprogrammersnotes.info%2F2009%2F03%2F03%2Fdifference-between-adapter-and-template-method-pattern%2F&amp;t=Difference+between+Adapter+and+Template+Method+pattern" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://programmersnotes.info/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
<a style="font-size:90%;text-align: right; " title="Click me to hide the sites." href="#" onclick="$$('div.d99').each( function(e) { e.visualEffect('slide_up',{duration:0.5}) }); return false;">Hide Sites</a>
</div>
</div>
<!-- Social Bookmarks END -->
<script type="text/javascript">$$('div.d99').each( function(e) { e.visualEffect('slide_up',{duration:0.5}) }); </script>

<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://yarpp.org'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://programmersnotes.info/2009/03/03/difference-between-adapter-and-template-method-pattern/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

