<?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>Bradley Holt &#187; Software Design</title>
	<atom:link href="http://bradley-holt.com/tag/software-design/feed/" rel="self" type="application/rss+xml" />
	<link>http://bradley-holt.com</link>
	<description></description>
	<lastBuildDate>Thu, 17 May 2012 01:04:35 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
		<item>
		<title>Entity Relationships in a Document Database</title>
		<link>http://bradley-holt.com/2012/05/entity-relationships-in-a-document-database/</link>
		<comments>http://bradley-holt.com/2012/05/entity-relationships-in-a-document-database/#comments</comments>
		<pubDate>Thu, 17 May 2012 01:04:35 +0000</pubDate>
		<dc:creator>Bradley Holt</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Boston]]></category>
		<category><![CDATA[Couchbase]]></category>
		<category><![CDATA[CouchConf]]></category>
		<category><![CDATA[CouchDB]]></category>
		<category><![CDATA[NoSQL]]></category>
		<category><![CDATA[Software Design]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://bradley-holt.com/?p=1546</guid>
		<description><![CDATA[This week I attended and presented at CouchConf Boston. I&#8217;d like to thank Couchbase for inviting me to speak—it was a great opportunity to meet other CouchDB and Couchbase users. I&#8217;ve posted the slides from my Entity Relationships in a Document Database talk to Speaker Deck (and SlideShare, if you prefer): The presentation covered four [...]]]></description>
			<content:encoded><![CDATA[<p>This week I attended and presented at CouchConf Boston. I&#8217;d like to thank <a href="http://www.couchbase.com/">Couchbase</a> for inviting me to speak—it was a great opportunity to meet other CouchDB and Couchbase users. I&#8217;ve posted the slides from my <a href="https://speakerdeck.com/u/bradleyholt/p/entity-relationships-in-a-document-database-at-couchconf-boston">Entity Relationships in a Document Database talk to Speaker Deck</a> (and <a href="http://www.slideshare.net/bradley.holt/entity-relationships-in-a-document-database-at-couchconf-boston">SlideShare</a>, if you prefer):<br />
<script async class="speakerdeck-embed" data-id="4fb26ea25a67ef03a500dc41" data-ratio="1.3333333333333333" src="//speakerdeck.com/assets/embed.js"></script><br />
The presentation covered four patterns for modeling entity relationships in document databases such as CouchDB and Couchbase:</p>
<ul>
<li>Embedded Entities</li>
<li>Related Documents</li>
<li>List of Keys</li>
<li>Relationship Documents</li>
</ul>
<p>See the presentation for more details. This topic is also covered in the <em>MapReduce Views for SQL Users</em> chapter in the second edition of <a href="http://shop.oreilly.com/product/0636920018247.do">Writing and Querying MapReduce Views in CouchDB</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://bradley-holt.com/2012/05/entity-relationships-in-a-document-database/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>The MVC Paradox</title>
		<link>http://bradley-holt.com/2012/04/the-mvc-paradox/</link>
		<comments>http://bradley-holt.com/2012/04/the-mvc-paradox/#comments</comments>
		<pubDate>Thu, 05 Apr 2012 17:27:23 +0000</pubDate>
		<dc:creator>Bradley Holt</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[Domain-Driven Design]]></category>
		<category><![CDATA[HTTP]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[Slim]]></category>
		<category><![CDATA[Software Design]]></category>
		<category><![CDATA[Web Application Frameworks]]></category>

		<guid isPermaLink="false">http://bradley-holt.com/?p=1503</guid>
		<description><![CDATA[Use of the Model View Controller (MVC) design pattern is generally accepted as a best practice in modern web applications. Like all design patterns, MVC is a reusable solution to a common problem. The MVC pattern is intended to address the following concerns: Support for multiple types of clients Reduce duplicate code when supporting multiple [...]]]></description>
			<content:encoded><![CDATA[<p>Use of the Model View Controller (MVC) design pattern is generally accepted as a best practice in modern web applications. Like all design patterns, MVC is a reusable solution to a common problem. The MVC pattern is intended to address the following concerns:</p>
<ol>
<li>Support for multiple types of clients</li>
<li>Reduce duplicate code when supporting multiple types of clients</li>
<li>Isolating domain logic from the user interface</li>
</ol>
<p>Note that items 2 and 3 are both dependent on item 1. <em>Support for multiple types of clients is the single driving force behind the MVC design pattern.</em> Following are some examples of client types:</p>
<ul>
<li>Web Browsers</li>
<li>API Clients</li>
<li>Admin Processes (e.g. CLI, cron, daemon)</li>
<li>Unit Tests</li>
<li>Native GUI</li>
</ul>
<p>Realistically, how many of these different client types do you need to support? If you&#8217;re taking a RESTful approach, then <a href="http://caines.ca/blog/programming/the-sun-is-setting-on-rails-style-mvc-frameworks/">Web Browsers and API Clients can be combined into one type of client</a>, which we can just call User Agents. Likely you&#8217;re not building a Native GUI. This leaves you with the following three types of clients to support:</p>
<ul>
<li>User Agents</li>
<li>Admin Processes</li>
<li>Unit Tests</li>
</ul>
<p>Do you really need to use the MVC design pattern in order to support User Agents, Admin Processes, and Unit Tests? Likely not. That&#8217;s not to say that there aren&#8217;t benefits to isolating domain logic from the user interface. However, if you don&#8217;t need to support multiple types of clients you should really question your use of the MVC design pattern. There are many approaches one can take to separating the domain logic and the user interface, of which MVC is just one.</p>
<p>This bring me to The MVC Paradox.<em> Modern MVC web frameworks inadvertently encourage the coupling of domain logic and user interface.</em> If you don&#8217;t need to support multiple types of clients, then decoupling the domain logic from the user interface is the only reason left to use the MVC design pattern.</p>
<p>Modern MVC web frameworks often involve a lot of boilerplate code just to support the primary client type of User Agents. This boilerplate code typically does little to help with supporting the other client types of Admin Processes and Unit Tests. As a result of the overhead introduced by this extra boilerplate code, developers often find themselves creating Fat Controllers (a side-effect of The MVC Paradox). Controllers take on too many responsibilities, both vertically and horizontally. Vertically, Controllers start to handle domain logic that should be pushed down to the Model layer. Horizontally, multiple concerns get stuffed into a handful of Controllers. These different horizontal concerns should be separated out into multiple Controllers (the Single Responsibility Principle). The overhead introduced by modern MVC web frameworks leads directly to these problems.</p>
<p>In contrast, take a look at the <a href="http://www.slimframework.com/">Slim PHP 5 micro framework</a>. While not a completely <a href="http://www.developerfusion.com/article/141194/evaluating-rest-frameworks-part-1-a-maturity-model/">RESTful framework</a>, it does a pretty good job of addressing the concerns I&#8217;ve laid out in this post. Here is the &#8220;Hello world&#8221; example from Slim&#8217;s homepage:</p>
<pre><code class="php">&lt;?php
require 'Slim/Slim.php';
$app = new Slim();
$app-&gt;get('/hello/:name', function ($name) {
    echo "Hello, $name!";
});
$app-&gt;run();
?&gt;</code></pre>
<p>There is very little boilerplate code involved in handling a User Agent&#8217;s request. Minting and handling new routes is incredibly simple. Placing your entire front-end application layer in one file may seem absurd at first. However, it has the nice side-effect of making it painfully obvious if you start to handle domain logic outside of your Model layer or if one route is doing too many things. If your front-end application is large enough, then you can <a href="http://www.slimframework.com/read/how-to-organize-a-large-slim-framework-application">organize your routes into separate files</a>.</p>
<p>This post is not intended to discourage you from using an MVC web framework. There are certainly times when such a framework is useful. As with any technology decision, carefully consider what problem you&#8217;re trying to solve and what technology will best address your problem set. Sometimes your technology choice can undermine the very purpose of using that technology in the first place, as is the case with The MVC Paradox.</p>
]]></content:encoded>
			<wfw:commentRss>http://bradley-holt.com/2012/04/the-mvc-paradox/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Top Five Posts of 2011</title>
		<link>http://bradley-holt.com/2011/12/top-five-posts-of-2011/</link>
		<comments>http://bradley-holt.com/2011/12/top-five-posts-of-2011/#comments</comments>
		<pubDate>Fri, 30 Dec 2011 17:15:32 +0000</pubDate>
		<dc:creator>Bradley Holt</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[AMQP]]></category>
		<category><![CDATA[CouchApp]]></category>
		<category><![CDATA[CouchDB]]></category>
		<category><![CDATA[Databases]]></category>
		<category><![CDATA[Domain-Driven Design]]></category>
		<category><![CDATA[FOSS]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[HTTP]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[NoSQL]]></category>
		<category><![CDATA[Open Standards]]></category>
		<category><![CDATA[OSCON]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[PHP-QAT]]></category>
		<category><![CDATA[Quality Assurance]]></category>
		<category><![CDATA[RabbitMQ]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[Scaling]]></category>
		<category><![CDATA[Software Design]]></category>

		<guid isPermaLink="false">http://bradley-holt.com/?p=1480</guid>
		<description><![CDATA[Continuing a trend started by Cal Evans and then followed by Chris Cornutt, Matthew Turland, and Joe Devon; here are the top five most viewed posts from my blog in 2011. 5. CouchDB and Domain-Driven Design This post covered two topics that are of great interest to me. Document databases like CouchDB have much potential [...]]]></description>
			<content:encoded><![CDATA[<p>Continuing a trend started by <a href="http://blog.calevans.com/2011/12/29/top-three-posts-of-2011/">Cal Evans</a> and then followed by <a href="http://blog.phpdeveloper.org/?p=425">Chris Cornutt</a>, <a href="http://matthewturland.com/2011/12/29/top-10-posts-of-2011/">Matthew Turland</a>, and <a href="http://mysqltalk.wordpress.com/2011/12/30/top-posts-of-2011/">Joe Devon</a>; here are the top five most viewed posts from my blog in 2011.</p>
<h3>5. <a href="http://bradley-holt.com/2011/08/couchdb-and-domain-driven-design/">CouchDB and Domain-Driven Design</a></h3>
<p>This post covered two topics that are of great interest to me. Document databases like CouchDB have much potential when it comes to domain-driven design. The post outlined some techniques for serializing domain objects into CouchDB documents.</p>
<h3>4. <a href="http://bradley-holt.com/2011/07/addressing-the-nosql-criticism/">Addressing the NoSQL Criticism</a></h3>
<p>I heard a lot of NoSQL bashing this year at OSCON. As a result, I decided to write a rebuttal to many of the criticisms that I heard. This post inspired a lively <a href="http://bradley-holt.com/2011/07/addressing-the-nosql-criticism/#comments">comment thread</a>.</p>
<h3>3. <a href="http://bradley-holt.com/2011/07/testing-php-5-4/">Testing PHP 5.4</a></h3>
<p>This was a short post on how to help the <a href="http://qa.php.net/">PHP Quality Assurance Team</a> by running the tests for the latest development version of PHP 5.4. It covered downloading, compiling, and running the tests. Most importantly, it also covered reporting your test results.</p>
<h3>2. <a href="http://bradley-holt.com/2011/07/exploring-rabbitmq-and-php/">Exploring RabbitMQ and PHP</a></h3>
<p>I was exploring the possibility of using RabbitMQ for an upcoming project. I decided to post some notes on my experience getting started with RabbitMQ and integrating it with PHP. I haven&#8217;t ended up using RabbitMQ in production yet, but I&#8217;m confident that I&#8217;ll end up using it at some point.</p>
<h3>1. <a href="http://bradley-holt.com/2011/07/couchdb-jquery-plugin-reference/">CouchDB jQuery Plugin Reference</a></h3>
<p>I had been frustrated by the lack of documentation for the CouchDB jQuery plugin—so decided to write my own. After I wrote the blog post, <a href="http://www.maxogden.com/">Max Ogden</a> pointed me to <a href="http://arandomurl.com/">Dale Harvey</a>‘s <a href="https://github.com/daleharvey/jquery.couch.js-docs">documentation generator for jquery.couch.js</a> and a copy of the generated <a href="http://daleharvey.github.com/jquery.couch.js-docs/symbols/index.html">jQuery CouchDB documentation</a>. Max and Dale are also working on a more flexible jquery.couch2.js.</p>
]]></content:encoded>
			<wfw:commentRss>http://bradley-holt.com/2011/12/top-five-posts-of-2011/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Twelve-Factor App Applied to PHP</title>
		<link>http://bradley-holt.com/2011/11/the-twelve-factor-app-applied-to-php/</link>
		<comments>http://bradley-holt.com/2011/11/the-twelve-factor-app-applied-to-php/#comments</comments>
		<pubDate>Tue, 29 Nov 2011 16:31:02 +0000</pubDate>
		<dc:creator>Bradley Holt</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Software Deployment]]></category>
		<category><![CDATA[Software Design]]></category>
		<category><![CDATA[Twelve-Factor App]]></category>
		<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://bradley-holt.com/?p=1451</guid>
		<description><![CDATA[If you develop web apps, I encourage you to check out The Twelve-Factor App. This is an excellent resource for anyone building and deploying software-as-a-service. PHP has great support for many of the twelve-factors. I want to take a look at specifically how each factor may be applied to a PHP application. I. Codebase &#8220;One [...]]]></description>
			<content:encoded><![CDATA[<p>If you develop web apps, I encourage you to check out <a href="http://www.12factor.net/">The Twelve-Factor App</a>. This is an excellent resource for anyone building and deploying software-as-a-service. PHP has great support for many of the twelve-factors. I want to take a look at specifically how each factor may be applied to a PHP application.</p>
<h3>I. <a href="http://www.12factor.net/codebase">Codebase</a></h3>
<blockquote><p>&#8220;One codebase tracked in revision control, many deploys&#8221;</p></blockquote>
<p>There&#8217;s really not much here that would be different in PHP versus any other language. Who isn&#8217;t using some form of revision control these days?</p>
<h3>II. <a href="http://www.12factor.net/dependencies">Dependencies</a></h3>
<blockquote><p>&#8220;Explicitly declare and isolate dependencies&#8221;</p></blockquote>
<p>There are a few tools available to PHP developers to help manage dependencies. The <a href="http://pear.php.net/">PEAR</a> package manager may help here, but has its flaws. <a href="http://pear2.php.net/PEAR2_Pyrus">Pyrus</a>, the PEAR2 package manager, looks promising. There&#8217;s also <a href="http://packagist.org/about-composer">Composer</a>. I&#8217;ve heard of people using their operating system&#8217;s package manager (e.g. RPM) to deploy their PHP applications and manage dependencies. I&#8217;m not sure if there any tools in PHP to enforce <em>dependency isolation</em>.</p>
<h3>III. <a href="http://www.12factor.net/config">Config</a></h3>
<blockquote><p>&#8220;Store config in the environment&#8221;</p></blockquote>
<p>The simplest option here is to use <em>environment variables</em>. Many frameworks, including Zend Framework, allow you to have environment-specific configuration such as <code>development</code>, <code>test</code>, and <code>production</code>. This is not recommended for twelve-factor apps as it doesn&#8217;t scale as new environments are added.</p>
<h3>IV. <a href="http://www.12factor.net/backing-services">Backing Services</a></h3>
<blockquote><p>&#8220;Treat backing services as attached resources&#8221;</p></blockquote>
<p>There&#8217;s not really anything to say here that&#8217;s specific to PHP.</p>
<h3>V. <a href="http://www.12factor.net/build-release-run">Build, release, run</a></h3>
<blockquote><p>&#8220;Strictly separate build and run stages&#8221;</p></blockquote>
<p><a href="http://www.phing.info/trac/">Phing</a> or the more general-purpose <a href="http://ant.apache.org/">Ant</a> could work here. Even though it&#8217;s not written in PHP, there&#8217;s no reason why you couldn&#8217;t use <a href="https://github.com/capistrano/capistrano/wiki">Capistrano</a> for this. I don&#8217;t think the <em>run stage</em> typically applies to PHP, as it happens implicitly as part of the <em>release stage</em>. However, there are tasks such as flushing the APC cache (if <code>apc.stat=0</code>) that might be considered part of the <em>run stage</em>.</p>
<h3>VI. <a href="http://www.12factor.net/processes">Processes</a></h3>
<blockquote><p>&#8220;Execute the app as one or more stateless processes&#8221;</p></blockquote>
<p>PHP processes are already stateless and <a href="http://en.wikipedia.org/wiki/Shared_nothing_architecture">shared-nothing</a>. This makes PHP a great fit for twelve-factor apps. Memory space or the filesystem should be used as a short-lived, single-process cache. If you&#8217;re using an asset manager, such as <a href="https://github.com/kriswallsmith/assetic">Assetic</a>, then any assets should be compiled and cached during the <a href="http://www.12factor.net/build-release-run">build stage</a>.</p>
<h3>VII. <a href="http://www.12factor.net/port-binding">Port binding</a></h3>
<blockquote><p>&#8220;Export services via port binding&#8221;</p></blockquote>
<p>I don&#8217;t think port binding applies to PHP applications—at least not in the way it&#8217;s meant in twelve-factor. PHP relies on a web server and uses something like <a href="http://www.fastcgi.com/">FastCGI</a> or <a href="http://php-fpm.org/">PHP-FPM</a> to communicate with the web server. PHP 5.4 will have its own built-in web server, but this is intended for development use only. It&#8217;s really the combination of PHP and its web server that will be bound to a port. This brings up challenges when it comes to dependency management, as the web server itself is now a dependency.</p>
<h3>VIII. <a href="http://www.12factor.net/concurrency">Concurrency</a></h3>
<blockquote><p>&#8220;Scale out via the process model&#8221;</p></blockquote>
<p>I&#8217;m not sure how processes would become first-class citizens in a PHP web application. However, each individual request/response cycle is handled by its own process. In that regard, PHP already uses the process model.</p>
<h3>IX. <a href="http://www.12factor.net/disposability">Disposability</a></h3>
<blockquote><p>&#8220;Maximize robustness with fast startup and graceful shutdown&#8221;</p></blockquote>
<p>PHP processes are very disposable. Again, this is just part of how PHP works.</p>
<h3>X. <a href="http://www.12factor.net/dev-prod-parity">Dev/prod parity</a></h3>
<blockquote><p>&#8220;Keep development, staging, and production as similar as possible&#8221;</p></blockquote>
<p>Nothing specific to PHP here. Although, it&#8217;s not uncommon for PHP developers to use SQLite in development and MySQL or PostgreSQL in production. This is not recommended for a twelve-factor app—use the same software and versions of <a href="http://www.12factor.net/backing-services">backing services</a> in all environments.</p>
<h3>XI. <a href="http://www.12factor.net/logs">Logs</a></h3>
<blockquote><p>&#8220;Treat logs as event streams&#8221;</p></blockquote>
<p>There are tons of logging options in PHP. <a href="http://framework.zend.com/manual/en/zend.log.writers.html#zend.log.writers.stream"><code>Zend_Log_Writer_Stream</code></a> lets you send log data to a <a href="http://www.php.net/stream">PHP stream</a>. Alternatively, <a href="http://codeascraft.etsy.com/2011/02/15/measure-anything-measure-everything/">StatsD and the PHP StatsD library</a> look pretty good.</p>
<h3>XII. <a href="http://www.12factor.net/admin-processes">Admin processes</a></h3>
<blockquote><p>&#8220;Run admin/management tasks as one-off processes&#8221;</p></blockquote>
<p>This is easy enough in PHP. If you want an interactive shell with readline history, tab completion, and quick access to documentation then check out <a href="http://www.phpsh.org/">phpsh</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://bradley-holt.com/2011/11/the-twelve-factor-app-applied-to-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Domain-Driven Design at ZendCon 2011 UnCon</title>
		<link>http://bradley-holt.com/2011/10/domain-driven-design-at-zendcon-2011-uncon/</link>
		<comments>http://bradley-holt.com/2011/10/domain-driven-design-at-zendcon-2011-uncon/#comments</comments>
		<pubDate>Wed, 19 Oct 2011 00:15:04 +0000</pubDate>
		<dc:creator>Bradley Holt</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Domain-Driven Design]]></category>
		<category><![CDATA[Software Design]]></category>
		<category><![CDATA[ZendCon]]></category>
		<category><![CDATA[ZendCon11]]></category>
		<category><![CDATA[ZendUncon]]></category>
		<category><![CDATA[ZendUncon11]]></category>

		<guid isPermaLink="false">http://bradley-holt.com/?p=1388</guid>
		<description><![CDATA[Here are the slides from today’s ZendCon UnCon session on Domain-Driven Design: ZendCon 2011 UnCon Domain-Driven Design View more presentations from Bradley Holt If you were in this session, please give me feedback on Joind.in.]]></description>
			<content:encoded><![CDATA[<p>Here are the slides from today’s ZendCon UnCon session on Domain-Driven Design:</p>
<div style="width:425px" id="__ss_9759014"> <strong style="display:block;margin:12px 0 4px"><a href="http://www.slideshare.net/bradley.holt/zendcon-2011-uncon-domain-driven-design" title="ZendCon 2011 UnCon Domain-Driven Design" target="_blank">ZendCon 2011 UnCon Domain-Driven Design</a></strong> <iframe src="http://www.slideshare.net/slideshow/embed_code/9759014" width="425" height="355" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>
<div style="padding:5px 0 12px"> View more <a href="http://www.slideshare.net/" target="_blank">presentations</a> from <a href="http://www.slideshare.net/bradley.holt" target="_blank">Bradley Holt</a> </div>
</p></div>
<p>If you were in this session, please <a href="http://joind.in/talk/view/4003">give me feedback on Joind.in</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://bradley-holt.com/2011/10/domain-driven-design-at-zendcon-2011-uncon/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CouchDB and Domain-Driven Design</title>
		<link>http://bradley-holt.com/2011/08/couchdb-and-domain-driven-design/</link>
		<comments>http://bradley-holt.com/2011/08/couchdb-and-domain-driven-design/#comments</comments>
		<pubDate>Tue, 02 Aug 2011 15:30:27 +0000</pubDate>
		<dc:creator>Bradley Holt</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[CouchDB]]></category>
		<category><![CDATA[Domain-Driven Design]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Software Design]]></category>

		<guid isPermaLink="false">http://bradley-holt.com/?p=1251</guid>
		<description><![CDATA[I&#8217;ve found CouchDB to be a great fit for domain-driven design (DDD). Specifically, CouchDB fits very well with the building block patterns and practices found within DDD. Two of these building blocks include Entities and Value Objects. Entities are objects defined by a thread of continuity and identity. A Value Object &#8220;is an object that [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve found CouchDB to be a great fit for <a href="http://en.wikipedia.org/wiki/Domain-driven_design">domain-driven design</a> (DDD). Specifically, CouchDB fits very well with the building block patterns and practices found within DDD. Two of these building blocks include <em><a href="http://domaindrivendesign.org/node/109">Entities</a></em> and <em><a href="http://domaindrivendesign.org/node/135">Value Objects</a></em>. Entities are objects defined by a thread of continuity and identity. A Value Object &#8220;is an object that describes some characteristic or attribute but carries no concept of identity.&#8221; Value objects should be treated as immutable.</p>
<p><em><a href="http://domaindrivendesign.org/node/88">Aggregates</a></em> are groupings of associated Entities and Value Objects. Within an Aggregate, one member is designated as the <em>Aggregate Root</em>. External references are limited to only the Aggregate Root. Aggregates should follow transaction, distribution, and concurrency boundaries. Guess what else is defined by transaction, distribution, and concurrency boundaries? That&#8217;s right, JSON documents in CouchDB.</p>
<p>Let&#8217;s take a look at an example Aggregate, that representing a blog entry and related metadata. Note that the following UML diagrams are for classes in PHP, but it should be easy enough to translate these examples to any object-oriented programming language. We&#8217;ll start with the <code>Entry</code> Entity, which will serve as our Aggregate Root:</p>
<pre>-----------------------------------------
|                 Entry                 |
-----------------------------------------
|+ id : string                          |
|+ rev : string                         |
|+ title : Text                         |
|+ updated : Date                       |
|+ authors : Person[*]                  |
|+ content : Text                       |
-----------------------------------------
|+ __construct(entry : array) : void    |
|+ toArray() : array                    |
-----------------------------------------</pre>
<p>The <code>Text</code> Value Object:</p>
<pre>----------------------------------------------
|                    Text                    |
----------------------------------------------
|- type : string                             |
|- text : string                             |
----------------------------------------------
|+ __construct(type : string, text : string) |
|+ toArray() : array                         |
----------------------------------------------</pre>
<p>The <code>Date</code> Value Object:</p>
<pre>--------------------------------------
|                Date                |
--------------------------------------
|- timestamp : integer               |
--------------------------------------
|+ __construct(timestamp : integer)  |
|+ __toString() : string             |
--------------------------------------</pre>
<p>The <code>Person</code> Value Object:</p>
<pre>-------------------------------------------------------------
|                           Person                          |
-------------------------------------------------------------
|- name : string                                            |
|- uri : string                                             |
|- email : string                                           |
-------------------------------------------------------------
|+ __construct(name : string, uri : string, email : string) |
|+ toArray() : array                                        |
-------------------------------------------------------------</pre>
<p>I recommend serializing each Aggregate, starting with the Aggregate  Root, into a JSON document. Control access to Aggregate Roots  through a <em><a href="http://domaindrivendesign.org/node/123">Repository</a></em>. The <code>toArray()</code> methods above return an associative array representation of each object. The Repository can then transform the array into JSON for storage in CouchDB. Let&#8217;s take a look at the <code>EntryRepository</code>:</p>
<pre>---------------------------------
|        EntryRepository        |
---------------------------------
|                               |
---------------------------------
|+ get(id : string) : Entry     |
|+ post(entry : Entry) : void   |
|+ put(entry : Entry) : void    |
|+ delete(entry : Entry) : void |
---------------------------------</pre>
<p>Here&#8217;s an example of what the Aggregate&#8217;s object graph might look like, serialized as a JSON document:</p>
<pre><code class="javascript">{
    "_id": "http://bradley-holt.com/?p=1251",
    "title": {
        "type": "text",
        "text": "CouchDB and Domain-Driven Design"
    },
    "updated": "2011-08-02T15:30:00+00:00",
    "authors": [
        {
             "name": "Bradley Holt",
             "uri": "http://bradley-holt.com/",
             "email": "bradley.holt@foundline.com"
        }
    ],
    "content": {
        "type": "html",
        "text": "&lt;p&gt;I've found CouchDB to be a great fit for…&lt;/p&gt;"
    }
}</code></pre>
<p>You can also provide access to CouchDB views through Repositories. In the above example, this could be through the addition of an <code>index(skip : integer, limit : integer) : Entry[*]</code> method to the the <code>EntryRepository</code> (note that this is a naive pagination implementation, especially on large data sets—but that&#8217;s beyond the scope of this blog post). For more complex views, you may want to create a separate Repository for each CouchDB view.</p>
]]></content:encoded>
			<wfw:commentRss>http://bradley-holt.com/2011/08/couchdb-and-domain-driven-design/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Domain-Driven Design Immersion Class</title>
		<link>http://bradley-holt.com/2010/10/domain-driven-design-immersion-class/</link>
		<comments>http://bradley-holt.com/2010/10/domain-driven-design-immersion-class/#comments</comments>
		<pubDate>Sat, 02 Oct 2010 03:25:55 +0000</pubDate>
		<dc:creator>Bradley Holt</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Domain-Driven Design]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Software Design]]></category>

		<guid isPermaLink="false">http://bradley-holt.com/?p=876</guid>
		<description><![CDATA[I just wrapped up a four day Domain-Driven Design Immersion class with Eric Evans (author of Domain-Driven Design) and Paul Rayner. The class was put on by Eric&#8217;s company, Domain Language. If you&#8217;re looking for training or consulting in Domain-Driven Design, I highly recommend that you get in touch with them. I&#8217;d like to share [...]]]></description>
			<content:encoded><![CDATA[<p>I just wrapped up a four day Domain-Driven Design Immersion class with Eric Evans (author of <a href="http://domaindrivendesign.org/books/#DDD">Domain-Driven Design</a>) and <a href="http://www.virtual-genius.com/">Paul Rayner</a>. The class was put on by Eric&#8217;s company, <a href="http://www.domainlanguage.com/">Domain Language</a>. If you&#8217;re looking for training or consulting in Domain-Driven Design, I highly recommend that you get in touch with them. I&#8217;d like to share some highlights of the class here.</p>
<h3>Putting the Model To Work</h3>
<p>Domain-Driven Design is a set of three guiding principles:</p>
<ul>
<li>Focus on the <a href="http://domaindrivendesign.org/node/99">Core Domain</a> as that is where the complexity is. Technology plays a supporting role, use it as needed.</li>
<li>Explore the <a href="http://domaindrivendesign.org/node/120">Model</a> in a collaborative process involving both <a href="http://domaindrivendesign.org/node/107">Domain Experts</a> and software practitioners.</li>
<li>Speak a <a href="http://domaindrivendesign.org/node/132">Ubiquitous Language</a> within an explicitly <a href="http://domaindrivendesign.org/node/91">Bounded Context</a>.</li>
</ul>
<p>I should point out that the word &#8220;Model&#8221; has many different meanings in software development. Within Domain-Driven Design a Model is a &#8220;system of abstractions that describes selected aspects of a domain and can be used to solve problems related to that domain.&#8221; Those familiar with the Model–View–Controller (MVC) pattern should note that the word &#8220;Model&#8221; within the MVC pattern has a different meaning than &#8220;Model&#8221; within Domain-Driven Design. Within Domain-Driven Design a Model is a conceptual tool used to understand a <a href="http://domaindrivendesign.org/node/105">Domain</a>. An example that was used in the class was the game of baseball. A Model of the baseball Domain would include concepts such as strikes, balls, and outs. The classes and objects representing these concepts would <em>not</em> be the Model.</p>
<p>You might be wondering what the difference is between the Domain and the Model. The goal with Domain-Driven Design is <em>not</em> to create a Model of reality. Even if you could come up with some objective view of reality this would not be very useful. Instead, we are trying to understand (and perhaps develop) the Models that Domain Experts already use to understand the Domain. It&#8217;s important to note that Models are only useful <em>for a particular purpose</em>. What are you trying to do with this Model? Trying to use a Model designed for a different purpose will lead to a less than optimal outcome.</p>
<p>The <a href="http://www.domainlanguage.com/ddd/whirlpool/">Model Exploration Whirlpool</a> might be a useful reference if you&#8217;re looking for concrete guidance on how to explore Models, especially in an Agile or Lean setting.</p>
<h3>Building Blocks</h3>
<p>Group <a href="http://domaindrivendesign.org/node/109">Entities</a> and <a href="http://domaindrivendesign.org/node/135">Value Objects</a> into <a href="http://domaindrivendesign.org/node/88">Aggregates</a>. Entities are objects defined by a thread of continuity and identity. Their only responsibilities should be around identity and life cycle. Within a customer relationship management (CRM) system a person would likely be an Entity. Note that context matters: a person in another context may be a Value Object. A Value Object &#8220;is an object that describes some characteristic or attribute but carries no concept of identity.&#8221; Using the CRM example again, a phone number might be a Value Object. Again, context matters: if you&#8217;re a telephone company then a phone number may very well be an Entity. Treat Value Objects as immutable. Delegate business logic to Value Objects, identity and life cycle are plenty of responsibility for Entities. Grouping these Entities and Value Objects into Aggregates is useful when defining transaction, distribution, and concurrency boundaries.</p>
<p>An interesting topic covered in the class that I don&#8217;t believe was in  the book was the idea of Domain Events. A Domain Event is something  important that happens within the Domain that may lead to a state change  in a domain object. Instead of keeping track of the current state of an  Entity, you can instead compute this state from the currently known  Domain Events. Using a baseball analogy again, a Domain Event might be a  strike. Domain Events can trigger other Domain Events: three strikes  triggers an out. The current state of the game can be computed from all  of the Domain Events.</p>
<h3>Supple Design</h3>
<p>Since this has been a topic of conversation here on my blog and on Twitter, I plan on writing another blog post on why Value Objects need to be immutable. However, I want to point out here that if you think you need to change the state of a Value Object then instead have a method on that Value Object that returns another instance of the same type with the new state. If your method takes any arguments then have these arguments be of the same type as the Value Object. This concept is called &#8220;closure of operations&#8221; and is covered in Chapter 10 of the book, Supple Design.</p>
<p>While I won&#8217;t go into the details here, there are several other useful patterns in creating supple designs including intention-revealing interfaces, side-effect-free functions, and assertions. Note that &#8220;supple&#8221; is not the same as &#8220;flexible&#8221;. A flexible design can be easily modified, but a supple design is a design that fits comfortably with the Domain.</p>
<h3>Strategic Design</h3>
<p><a href="http://domaindrivendesign.org/node/130">Strategic Design</a> involves managing the interactions between Bounded Contexts. In my understanding, strategic design is most applicable in large teams or groups of teams. It starts by drawing a <a href="http://domaindrivendesign.org/node/98">Context Map</a> of the actual current Bounded Contexts, not what you want the Bounded Contexts to be. Some patterns to describe these relationships include Partnership, Shared Kernel, Big Ball of Mud, Customer/Supplier, Conformist, Anticorruption Layer, Separate Ways, Open Host Service, and Published Language. The details of these patterns can be found in the book.</p>
<h3>Distillation</h3>
<p>There are always multiple Models. Some of these Models my represent your Core Domain. Others may represent a Supporting Domain or a Generic Subdomain. Work with business leaders to create a Domain Vision Statement so that you can identify which is which. One good question to ask a Domain Expert at the outset of a project to get at the Core Domain is, &#8220;What keeps you awake at night?&#8221; Other questions to ask include:</p>
<ul>
<li>&#8220;What makes your system worth writing?&#8221;</li>
<li>&#8220;Why not buy it off the shelf?&#8221;</li>
<li>&#8220;Why not outsource it?&#8221;</li>
</ul>
<p>Once you&#8217;ve identified your Core Domain this is where you should focus your modeling efforts. Put your best available internal developers and modelers on the Core Domain and make sure that the Core Domain is isolated in a clean, Bounded Context.</p>
<h3>Summary</h3>
<p>Don&#8217;t settle on not having access to a Domain Expert. Domain-Driven Design is a creative collaboration between Domain Experts and software developers. Cultivate strong relationships with Domain Experts, focus on the Ubiquitous Language, listen for clues in conversations, and be open to <em>shifts in assumptions</em> that destroy your understanding of the Model—this is where breakthroughs come from!</p>
<p>If you&#8217;re interested in learning more:</p>
<ul>
<li>Watch Eric Evan&#8217;s <a href="http://www.infoq.com/presentations/model-to-work-evans">Putting the Model to Work</a> and <a href="http://www.infoq.com/presentations/strategic-design-evans">Strategic Design</a> presentations (note that slides are provided below the videos).</li>
<li>Read the <a href="http://domaindrivendesign.org/books#DDD">Domain-Driven Design</a> book.</li>
<li>Attend a <a href="http://www.domainlanguage.com/">Domain Language</a> class.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://bradley-holt.com/2010/10/domain-driven-design-immersion-class/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Immutable Value Objects in PHP</title>
		<link>http://bradley-holt.com/2010/09/immutable-value-objects-in-php/</link>
		<comments>http://bradley-holt.com/2010/09/immutable-value-objects-in-php/#comments</comments>
		<pubDate>Thu, 30 Sep 2010 18:26:20 +0000</pubDate>
		<dc:creator>Bradley Holt</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Domain-Driven Design]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Software Design]]></category>

		<guid isPermaLink="false">http://bradley-holt.com/?p=863</guid>
		<description><![CDATA[Yesterday I tweeted: Modern object-oriented programming languages need support for immutable Value Objects. #DDD The &#8220;DDD&#8221; in that tweet stands for Domain-Driven Design. There were several interesting responses to this tweet. Kevin Schroeder thought that it made a lot of sense but pointed out that &#8220;need&#8221; was a bit of a strong word. I should [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday I <a href="http://twitter.com/BradleyHolt/status/25911903352">tweeted</a>:</p>
<blockquote><p>Modern object-oriented programming languages need support for immutable Value Objects. <a href="http://twitter.com/search?q=%23DDD">#DDD</a></p></blockquote>
<p>The &#8220;DDD&#8221; in that tweet stands for <a href="http://en.wikipedia.org/wiki/Domain-driven_design">Domain-Driven Design</a>. There were several interesting responses to this tweet. Kevin Schroeder <a href="http://twitter.com/kpschrade/status/25912815439">thought that it made a lot of sense</a> but pointed out that &#8220;need&#8221; was a bit of a strong word. I should have instead said that this would be a &#8220;useful&#8221; feature. Matthew Weier O&#8217;Phinney shared an <a href="http://paste2.org/p/1009796">example of making an immutable object in PHP</a>. Ralph Schindler <a href="http://gist.github.com/603496">suggested throwing an exception</a> so as not to silently reject an attempt to modify the object&#8217;s state. Nicolas Bérard-Nault had a similar suggestion of <a href="http://twitter.com/nicolasbn/status/25942269645">implementing PHP&#8217;s <code>__set</code> magic method and throwing an exception</a> so that new public attributes cannot be assigned and also not making any methods that change the state of the object. Giorgio Sironi suggested that <a href="http://twitter.com/giorgiosironi/status/25914287997">PHP&#8217;s &#8220;private&#8221; keyword was all you needed to support immutable Value Objects</a>.</p>
<p>The above suggestions are all useful when implementing immutable Value Objects in PHP. I would also add that you need to make the class &#8220;final&#8221; to truly guarantee that it&#8217;s immutable. This is so that someone can&#8217;t extend the class and add (or override) methods that change state (although I suppose if you made the <code>__set</code> method final and had it throw an exception that should do the trick since you wouldn&#8217;t be able to change any properties).</p>
<p>Regardless, all of these attempts to guarantee immutability miss the point. I don&#8217;t need to make sure the class is immutable when its defined, I need to know in my client code that it&#8217;s immutable. In other words, I need a <em>contract</em> that says the object is immutable. None of the above workarounds give you an explicit contract that the object is immutable. Hopefully you&#8217;re working on a team where you trust that if a teammate tells you that something is an immutable Value Object, it is immutable. In fact, I wouldn&#8217;t normally bother doing any of the above tricks to absolutely guarantee that the object is immutable. This is because you still can&#8217;t tell by looking at the object that it is immutable without inspecting its implementation. A built-in language feature would be useful because it would provide an explicit contract that the object is immutable.</p>
]]></content:encoded>
			<wfw:commentRss>http://bradley-holt.com/2010/09/immutable-value-objects-in-php/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Domain-Driven Design</title>
		<link>http://bradley-holt.com/2009/07/domain-driven-design/</link>
		<comments>http://bradley-holt.com/2009/07/domain-driven-design/#comments</comments>
		<pubDate>Wed, 29 Jul 2009 17:25:00 +0000</pubDate>
		<dc:creator>Bradley Holt</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Software Design]]></category>
		<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://bradley-holt.com/2009/07/domain-driven-design/</guid>
		<description><![CDATA[I am currently reading Eric Evans&#8217; Domain-Driven Design book. Having read most of the book I can say that his presentations on Putting the Model to Work and Strategic Design are an amazingly concise overview of the book&#8217;s content (note that InfoQ provides slides below the videos). If you&#8217;ve been interested in reading the book [...]]]></description>
			<content:encoded><![CDATA[<p>I am currently reading Eric Evans&#8217; <a href="http://domaindrivendesign.org/books#DDD">Domain-Driven Design</a> book. Having read most of the book I can say that his presentations on <a href="http://www.infoq.com/presentations/model-to-work-evans">Putting the Model to Work</a> and <a href="http://www.infoq.com/presentations/strategic-design-evans">Strategic Design</a> are an amazingly concise overview of the book&#8217;s content (note that InfoQ provides slides below the videos). If you&#8217;ve been interested in reading the book but just haven&#8217;t had time yet then I&#8217;d recommend watching these two presentations.</p>
<p>I have a lot of experience building web applications that separate business logic from presentation and have been using Zend Framework&#8217;s <a href="http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller">model–view–controller</a> (MVC) components for over two years now. This has certainly helped make web applications I work on more maintainable. However, creating effective models (the &#8220;M&#8221; in &#8220;MVC&#8221;) has always been difficult (this has nothing to do with Zend Framework and has everything to do with the difficulty of modeling in general). The Zend Framework team has been relatively quiet on models since modeling tends to be specific to your application&#8217;s domain (although Matthew Weier O&#8217;Phinney recently gave a great <a href="http://www.phparch.com/main/news/view/51/The_Recording_for_Friday_s_Webcast_is_Now_Available">webcast</a> and <a href="http://www.slideshare.net/weierophinney/playdoh-modelling-your-objects-1766001">presentation</a> on modeling in Zend Framework).</p>
<p>The Domain-Driven Design book has helped make a lot of things &#8220;click&#8221; for me. It drives home the point that modeling is a domain-specific task and that the complexity is usually in the domain, not the technical aspects of your project. If you think the complexity is in the technology then you should question your choice of tools (in my opinion) but in this case perhaps domain-driven design isn&#8217;t right for you. The book provides many patterns that help keep the focus on the domain. Arguably the most important of these patterns is the <a href="http://domaindrivendesign.org/node/132">Ubiquitous Language</a> which is &#8220;a language structured around the domain model and used by all team members to connect all the activities of the team with the software.&#8221; Other important patterns include <a href="http://domaindrivendesign.org/node/109">Entities</a>, <a href="http://domaindrivendesign.org/node/135">Value Objects</a>, <a href="http://domaindrivendesign.org/node/125">Services</a>, <a href="http://domaindrivendesign.org/node/123">Repositories</a> and <a href="http://domaindrivendesign.org/node/110">Factories</a>.</p>
<p>If effective modeling has been something that you&#8217;ve struggled with then I&#8217;d urge you to check out Eric Evans&#8217; presentations and then read his Domain-Driven Design book.</p>
]]></content:encoded>
			<wfw:commentRss>http://bradley-holt.com/2009/07/domain-driven-design/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>API Design</title>
		<link>http://bradley-holt.com/2008/03/api-design/</link>
		<comments>http://bradley-holt.com/2008/03/api-design/#comments</comments>
		<pubDate>Mon, 31 Mar 2008 20:15:00 +0000</pubDate>
		<dc:creator>Bradley Holt</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Software Design]]></category>

		<guid isPermaLink="false">http://bradley-holt.com/2008/03/api-design/</guid>
		<description><![CDATA[Artima has an older (but still relevant and interesting) interview with Josh Bloch, a Sun Microsystems Architect. While the interview focuses on Java, Josh Bloch has some interesting things to say about software design in general. The main topic is thinking about design in terms of APIs instead of monolithic software construction. Reuse is extremely [...]]]></description>
			<content:encoded><![CDATA[<p>Artima has an older (but still relevant and interesting) <a href="http://www.artima.com/intv/bloch.html">interview with Josh Bloch</a>, a Sun Microsystems Architect.  While the interview focuses on Java, Josh Bloch has some interesting things to say about software design in general. The main topic is thinking about design in terms of APIs instead of monolithic software construction.<br />
<blockquote>Reuse is extremely important but difficult to achieve. You don&#8217;t get it for free, but it is achievable.</p></blockquote>
<p> The lure of object-oriented programming is the ability to reuse code. However, creating reusable code is not as simple as switching from procedural to object-oriented programming. One may make the switch from procedural to object-oriented programming and then be disappointed that object-oriented programming didn&#8217;t deliver on the promise of reuse. Josh Bloch has a potential solution to this problem but it requires one to think about software in terms of public APIs.</p>
<p>Being disappointed with object-oriented programming, one may then decide to try agile programming, perhaps even extreme programming. One tenant of extreme programming is to &#8220;do the simplest thing that could possible work.&#8221; Josh Bloch points out that this is easy to misconstrue:</p>
<blockquote><p>The extreme programming proponents don&#8217;t advocate writing something that will barely work as fast as you can. They don&#8217;t advise you to forgo any design. They do advocate leaving out the bells, whistles, and features you don&#8217;t need and add them later, if a real need is demonstrated. And that&#8217;s incredibly important, because you can always add a feature, but you can never take it out. Once a feature is there, you can&#8217;t say, sorry, we screwed up, we want to take it out because other code now depends on it. People will scream. So, when in doubt, leave it out.</p></blockquote>
<p> He goes on to talk about other topics such as minimizing mutability, protected vs. private members, when to make a class final, and the copy constructor as a cloning mechanism. It is interesting reading if you are striving for the goal of reusable object-oriented code.</p>
]]></content:encoded>
			<wfw:commentRss>http://bradley-holt.com/2008/03/api-design/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

