<?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>Cranky Bit &#187; General Web Dev.</title>
	<atom:link href="http://blog.crankybit.com/tag/webdev/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.crankybit.com</link>
	<description>Take a byte out of tech!</description>
	<lastBuildDate>Wed, 09 Mar 2011 17:23:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Memento Pattern is Great for Web Services</title>
		<link>http://blog.crankybit.com/memento-pattern-is-great-for-web-services/</link>
		<comments>http://blog.crankybit.com/memento-pattern-is-great-for-web-services/#comments</comments>
		<pubDate>Fri, 02 May 2008 21:34:28 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
				<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[General Web Dev.]]></category>
		<category><![CDATA[Transfer]]></category>

		<guid isPermaLink="false">http://blog.crankybit.com/?p=298</guid>
		<description><![CDATA[Nothing Earth-shattering here. I've just come to appreciate how useful the memento design pattern can be to do web services a bit more efficiently sometimes. My web service is a facade CFC powered by objects being generated by Transfer and ColdSpring. So I conveniently have access to the objects' getMemento() or getPropertyMemento() methods. I had [...]]]></description>
			<content:encoded><![CDATA[<p>Nothing Earth-shattering here. I've just come to appreciate how useful the <a href="http://en.wikipedia.org/wiki/Memento_pattern" target="_blank">memento design pattern</a> can be to do web services a bit more efficiently sometimes.</p>
<p>My web service is a facade CFC powered by objects being generated by Transfer and ColdSpring. So I conveniently have access to the objects' <strong>getMemento()</strong> or <strong>getPropertyMemento()</strong> methods.</p>
<p>I had a method in the web service that would accept several arguments and perform the simple task of processing them and saving them to the database. It returned a single boolean indicating success or failure.</p>
<p>The web service is just used by another web server that doesn't have access to the database and can't run Transfer (because it is currently running CFMX 6). This web server hosts a page with a form; when the user submits the form, the action page invokes the web service to process and save the information.</p>
<p>I needed the action page to display some data that wasn't available in the form data that was transmitted. For instance, a pull-down menu allowed the user to select from a list of sessions, but all that is transmitted is the database ID of the session they chose. My action page can't display any details about that session unless it makes another web service call to retrieve the details of that session. <em>And </em>I have to write the code for that web service method, which up to this point was unnecessary.</p>
<p>Aha! I changed the web service to return a <strong>struct</strong> that still contained the success/failure boolean, but also contained mementos of the objects that were created or referenced when processing the request. Now my web server invoking the web service has all the details of the session at its disposal for display on the action page.</p>
<p>What's the big deal, right? Who cares about one more web service call? Well, I'd like to keep the chatter between the two machines down to a minimally required amount, and besides, thanks to <strong>getMemento()</strong>, adding all of that data to the web service's response took one line of code, and way less time than it would take to write that extra web service method to retrieve session data, and also way less time than it took to even write this blog post. <img src='http://blog.crankybit.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>Here's the general thought process of the code in the web service (abbreviated to just show the point of mementos):</p>
<p>
<div class="igBar"><span id="lcfm-2"><a href="#" onclick="javascript:showCodeTxt('cfm-2'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CFM:</span>
<div id="cfm-2">
<div class="cfm">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #333333;"><span style="color: #990000;">&lt;cffunction</span> <span style="color: #0000FF;">name</span>=<span style="color: #009900;">"add"</span> <span style="color: #0000FF">access</span>=<span style="color: #009900;">"remote"</span> returntype=<span style="color: #009900;">"struct"</span><span style="color: #990000;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000099;"><span style="color: #990000;">&lt;cfscript&gt;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #000000; font-weight: bold;">var</span> ret=<span style="color: #0000FF;">StructNew</span><span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #000000; font-weight: bold;">var</span> mySession=SessionService.getSession<span style="color: #0000FF;">&#40;</span>Arguments.SID<span style="color: #0000FF;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #808080; font-style: italic; background-color:#FFFF99;">/* Do Processing */</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; ret.Success=true;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; ret.Session=mySession.getMemento<span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #990000;">&lt;/cfscript&gt;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #990000;">&lt;cfreturn</span> ret&gt;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #990000;">&lt;/cffunction&gt;</span> </span></div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.crankybit.com/memento-pattern-is-great-for-web-services/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

