<?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>Agile at Work &#187; Specification Pattern</title>
	<atom:link href="http://www.agileatwork.com/tag/specification-pattern/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.agileatwork.com</link>
	<description>by Michael Valenty</description>
	<lastBuildDate>Sat, 10 Sep 2011 14:35:33 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>This Could Have Been a Stored Procedure</title>
		<link>http://www.agileatwork.com/this-could-have-been-a-stored-procedure/</link>
		<comments>http://www.agileatwork.com/this-could-have-been-a-stored-procedure/#comments</comments>
		<pubDate>Fri, 12 Jun 2009 05:44:27 +0000</pubDate>
		<dc:creator>Michael Valenty</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Domain Driven Design]]></category>
		<category><![CDATA[Specification Pattern]]></category>

		<guid isPermaLink="false">http://www.agileatwork.com/this-application-could-have-been-a-stored-procedure/</guid>
		<description><![CDATA[ I read Domain Driven Design about a year and a half ago and when I got to the part about the specification pattern, I thought it was really cool and I couldn’t wait to try it out. Maybe the pattern gods were listening or maybe I was unknowingly using the secret. Either way, it [...]]]></description>
			<content:encoded><![CDATA[<p><img title="domain-driven-design-book-cover" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; margin: 0px 0px 0px 10px; border-right-width: 0px" height="196" alt="domain-driven-design-book-cover" src="http://www.agileatwork.com/wp-content/uploads/2009/06/domaindrivendesignbookcover.jpg" width="150" align="right" border="0" /> I read <a href="http://www.amazon.com/Domain-Driven-Design-Tackling-Complexity-Software/dp/0321125215">Domain Driven Design</a> about a year and a half ago and when I got to the part about the specification pattern, I thought it was really cool and I couldn’t wait to try it out. Maybe the pattern gods were listening or maybe I was unknowingly using <a href="http://www.thesecret.tv/">the secret</a>. Either way, it was pretty much the next morning that I went to work and had the perfect project dropped in my lap.</p>
<p>Our phone system routes live phone calls to doctor’s offices and the project was to bill the doctor if the call met the following criteria:</p>
<p>1) Caller is a new patient (pressed “1” instead of “2” in response to a voice prompt)</p>
<p>2) A live call was connected for more than 20 seconds or message longer than 10 seconds was recorded.</p>
<p>3) The doctor has not already been billed for this caller.</p>
<p>4) The call is not from a known list of test numbers.</p>
<p>The application subscribes to an event stream of new call records and runs them through this composite specification to determine if the call is billable.</p>
<pre class="prettyprint">
<code>public bool IsBillable(CallRecord call)
{
    ISpecification&lt;CallRecord&gt; billableCallSpecification = new NewPatient()
        .And(new MinLengthLiveCall(liveCallSeconds).Or(new MinLengthMessage(messageSeconds))
        .And(new RepeatCall(referralFinder).Not())
        .And(new TestCall(testNumbers).Not()));

    return billableCallSpecification.IsSatisfiedBy(call);
}</code>
</pre>
<p>I have to admit that I was already an hour into Query Analyzer blasting through another monster stored procedure when I caught myself. Not just the criteria logic either, I mean bypassing all the event stream hooha and basically just writing the whole enchilada as one gnarly stored procedure that would run as a job. That was a close one!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.agileatwork.com/this-could-have-been-a-stored-procedure/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

