<?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>Pols Consulting &#187; Refactoring</title>
	<atom:link href="http://www.pols.co.uk/archives/category/refactoring/feed" rel="self" type="application/rss+xml" />
	<link>http://www.pols.co.uk</link>
	<description>delivering software in the real world...</description>
	<lastBuildDate>Wed, 23 Jun 2010 22:29:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
		<item>
		<title>Martin Fowler has blogged about my Paper</title>
		<link>http://www.pols.co.uk/archives/35</link>
		<comments>http://www.pols.co.uk/archives/35#comments</comments>
		<pubDate>Tue, 29 Jun 2004 14:04:50 +0000</pubDate>
		<dc:creator>andy</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[Business Value]]></category>
		<category><![CDATA[Refactoring]]></category>

		<guid isPermaLink="false">http://dev.pols.co.uk/wordpress/?p=35</guid>
		<description><![CDATA[Martin Fowler has blogged the idea of a Strangler Application based the work Chris Stevenson and I presented in our An Agile Approach to A Lagacy System paper. Here are some interesting comments about our approach: &#8230; Much of my career has involved rewrites of critical systems. You would think such a thing as easy [...]]]></description>
			<content:encoded><![CDATA[<p>Martin Fowler has <a href="http://www.martinfowler.com/bliki/StranglerApplication.html">blogged</a> the idea of a <strong>Strangler Application</strong> based the work <a href="http://www.skizz.biz/">Chris Stevenson</a> and I presented in our <a href="http://www.pols.co.uk/papers/agile-approach-to-legacy-systems.pdf">An Agile Approach to A Lagacy System</a> paper.</p>
<p>Here are some interesting comments about our approach:</p>
<blockquote><p>&#8230; Much of my career has involved rewrites of critical systems. You would think such a thing as easy &#8211; just make the new one do what the old one did. Yet they are always much more complex than they seem, and overflowing with risk. The big cut-over date looms, the pressure is on. While new features (there are always new features) are liked, old stuff has to remain. Even old bugs often need to be added to the rewritten system.</p>
<p>An alternative route is to gradually create a new system around the edges of the old, letting it grow slowly over several years until the old system is strangled.</p>
<p>The most important reason to consider a strangler application over a cut-over rewrite is reduced risk. A strangler can give value steadily and the frequent releases allow you to monitor its progress more carefully&#8230;</p></blockquote>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fwww.pols.co.uk%2Farchives%2F35';
  addthis_title  = 'Martin+Fowler+has+blogged+about+my+Paper';
  addthis_pub    = 'andy_pols';
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>
]]></content:encoded>
			<wfw:commentRss>http://www.pols.co.uk/archives/35/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Using Aliases to refactor XML</title>
		<link>http://www.pols.co.uk/archives/16</link>
		<comments>http://www.pols.co.uk/archives/16#comments</comments>
		<pubDate>Tue, 24 Feb 2004 01:59:40 +0000</pubDate>
		<dc:creator>andy</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[Refactoring]]></category>
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://dev.pols.co.uk/wordpress/?p=16</guid>
		<description><![CDATA[I have been playing with XStream for converting java classes into xml. We can convert a class such as this: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 package xtream.demo; &#160; import java.util.Date; &#160; public class NotVeryUsefulBean &#123; public String someString; public Date someDate; public int someInt; &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>I have been playing with <a href="http://xstream.codehaus.org">XStream</a> for converting java classes into xml.</p>
<p>We can convert a class such as this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">xtream.demo</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Date</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> NotVeryUsefulBean <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> someString<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Date</span> someDate<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> someInt<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> NotVeryUsefulBean<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> someString, <span style="color: #003399;">Date</span> someDate, <span style="color: #000066; font-weight: bold;">int</span> someInt<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">someString</span> <span style="color: #339933;">=</span> someString<span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">someDate</span> <span style="color: #339933;">=</span> someDate<span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">someInt</span> <span style="color: #339933;">=</span> someInt<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>into xml that looks like this.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xtream</span> .demo.NotVeryUsefulBean<span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;somestring<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Sample String<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/somestring<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;somedate<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>2006-07-22 14:45:02.117 PM<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/somedate<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;someint<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>999<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/someint<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xtream<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>The xml is nice and clean.  Like most implementations, XStream embeds the name of the class in the xml. This can cause problems when you rename a class, or move it to a different package.  The xml could be on  a customers&#8217; machine, well away from my refactoring IDE.  I have been bitten by this lately.</p>
<p>Then I realised that XStream has aliases.  Joe added aliases to make it easier to read the xml.  You  map an alias to a class. Here is an example of using a &#8220;MyAlias&#8221; for the &#8220;NotVeryUsefulBean&#8221; class.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.thoughtworks.xstream.XStream</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">xtream.demo.NotVeryUsefulBean</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Date</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> XstreamDemoUsingAnAlias<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        XStream xStream <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> XStream<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        xStream.<span style="color: #006633;">alias</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;MyAlias&quot;</span>, NotVeryUsefulBean.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        NotVeryUsefulBean bean <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> NotVeryUsefulBean<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;String&quot;</span>, <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Date</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, <span style="color: #cc66cc;">999</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #003399;">String</span> xml <span style="color: #339933;">=</span> xStream.<span style="color: #006633;">toXML</span><span style="color: #009900;">&#40;</span>bean<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;xml = &quot;</span> <span style="color: #339933;">+</span> xml<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>And the xml now looks like this</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;myalias<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;somestring<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>String<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/somestring<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;somedate<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>2006-07-22 15:02:37.996 PM<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/somedate<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;someint<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>999<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/someint<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/myalias<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>Not a class name in sight. When I rename classes and move them into different packages, the refactoring tool will update the alias without breaking the xml. Nice!</p>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fwww.pols.co.uk%2Farchives%2F16';
  addthis_title  = 'Using+Aliases+to+refactor+XML';
  addthis_pub    = 'andy_pols';
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>
]]></content:encoded>
			<wfw:commentRss>http://www.pols.co.uk/archives/16/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
