<?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>JTeam Blog &#187; Domain Driven Design</title>
	<atom:link href="http://blog.jteam.nl/tag/domain-driven-design/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.jteam.nl</link>
	<description>Keep updated on what we&#039;re doing!</description>
	<lastBuildDate>Fri, 23 Jul 2010 07:32:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Axon Framework &#8211; the CQRS framework for Java &#8211; version 0.4 released</title>
		<link>http://blog.jteam.nl/2010/02/21/axon-framework-the-cqrs-framework-for-java-version-0-4-released/</link>
		<comments>http://blog.jteam.nl/2010/02/21/axon-framework-the-cqrs-framework-for-java-version-0-4-released/#comments</comments>
		<pubDate>Sun, 21 Feb 2010 16:04:09 +0000</pubDate>
		<dc:creator>Allard Buijze</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Axon Framework]]></category>
		<category><![CDATA[CQRS]]></category>
		<category><![CDATA[DDD]]></category>
		<category><![CDATA[Domain Driven Design]]></category>
		<category><![CDATA[Open Source]]></category>

		<guid isPermaLink="false">http://blog.jteam.nl/2010/02/21/axon-framework-the-cqrs-framework-for-java-version-0-4-released/</guid>
		<description><![CDATA[Last week, I published the 0.4 release of the Axon Framework. Axon helps developers build high performance, scalable and extensible applications using the CQRS pattern. The 0.4 release is a major step towards 1.0, and includes transactional event handling, high-performance caching repositories and easy configuration of event sourcing support. Furthermore, we have also built a [...]]]></description>
			<content:encoded><![CDATA[<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; margin-left: 0px; border-left-width: 0px; margin-right: 0px" title="logo" border="0" alt="logo" align="left" src="http://blog.jteam.nl/wp-content/uploads/2010/02/logo.png" width="100" height="100" />Last week, I published the 0.4 release of the Axon Framework. Axon helps developers build high performance, scalable and extensible applications using the CQRS pattern. The 0.4 release is a major step towards 1.0, and includes transactional event handling, high-performance caching repositories and easy configuration of event sourcing support. Furthermore, we have also built a demo application that uses Flex to get real-time updates pushed from the server.</p>
<p>Read on to find out more.</p>
<p> <span id="more-1799"></span><br />
<h2>About the Axon Framework</h2>
<p><a name="Axon_Framework"></a></p>
<p>Axon Framework helps build scalable, extensible and maintainable applications by supporting developers apply the Command Query Responsibility Segregation (CQRS) architectural pattern. It does so by providing implementations, sometimes complete, sometimes abstract, of the most important building blocks, such as aggregates, repositories and event the bus – the dispatching mechanism for events. Furthermore, Axon provides annotation support, which allows you to build aggregates and event listeners without tying your code to Axon specific logic. This allows you to focus on your business logic, instead of the plumbing, and helps you makes your code easier to test in isolation.</p>
<h2>Features available in 0.4</h2>
<p>We have made quite a few additions and changes since the 0.3 release. Unfortunately, this also means I had to make some minor API changes. There is now a bigger choice of abstract classes for most of the building blocks. This allows you to choose whether you want to use the logic provided by Axon, or prefer to develop more of your own. Whatever your wish is, there should be a class to help you on your way.</p>
<p>The biggest change since 0.3 is the addition of an Asynchronous Event Bus that supports transactional processing of events. Since it is asynchronous, it means that your command processing doesn’t have to wait for events to be processed. However, this Event Buss can also guarantee the order in which events are delivered to the event handlers. You can choose full concurrent processing (without any guarantees about ordering), full sequential processing (FiFo guarantee) or anything in between. You could, for example, guarantee the sequential processing of Events that come from the same aggregate.</p>
<p>The Event Bus also provides transaction support. That means you can tell the event bus to retry an event after a certain amount of time when processing fails, for example due to an error in the underlying mechanism, such as a database. For performance reasons, you can configure the event handler to process multiple events within a single transaction. Database updates are a lot faster if you process several events within a single transaction before committing it. Within your event handler, you can configure transactions. </p>
<p>Besides Domain Events, Axon now also allows you to explicitly define two other types of events: Application Events and System Events. Application Event can notify your event listeners that something interesting happened in your application. System Events are a special type of application events and can be used to indicate that a part of your application has changed state, for example when the database is no longer available. These System Events could provide interesting operational information about your application.</p>
<p>Another major change since 0.3 is the documentation. We have brought the documentation up to par with the code-base. All features are now extensively described in the reference guide. You can download the manual from the Axon Framework website: <a href="http://www.axonframework.org" target="_blank">www.axonframework.org</a>.</p>
<p>Last, but definitely not least, we have created a demo application that you can easily download and deploy to have a look at how you can use events to your advantage. This demo application is built using a Flex Client and an Axon-based server side component. The Flex Client registers itself as an event listener and will automatically process incoming events, at real time! That means that you can have 2 windows open, change something in one window, and see the change come in immediately on the other window, too. Check our <a href="http://code.google.com/p/axonframework/wiki/SampleInstallation" target="_blank">Sample Installation</a> page for more information.</p>
<h2>What to expect in upcoming releases</h2>
<p>The major components of the CQRS pattern are already available in the 0.4 release of Axon Framework. However, there is still a number of features we want to include in the 1.0 release. Although one of the advantages of CQRS is that it makes an application scalable and extensible, the 1.0 release of Axon Framework focuses on what happens inside a single JVM. Streaming events between JVM’s is not made impossible though, the Spring Integration connectors can be used to publish events to JMS, MQ, mail, HTTP and any other protocol supported by Spring Integration.</p>
<p>Some features to expect before the 1.0 release are rolling snapshots. When aggregates live for a long time, the number of events to read in each time the aggregate is loaded could easily run in the thousands. Reading in a thousand events takes a long time. Instead of reading in a thousand events, you can summarize all these events into a single snapshot event. Axon Framework will provide the plumbing necessary for you to build snapshot events.</p>
<p>Another feature that we’ll be spending some attention on is failure recovery. Unfortunately, applications sometimes behave unexpectedly and sometimes stop entirely. The reason of a crash won’t be the Axon Framework itself, of course. But since we have a reliable source of events in the events store, we can use this to recover from failure. Axon Framework will provide some building blocks that allow you to republish events to event handlers that did not get the chance to process them. This same mechanism will allow you to restore your application state from backups.</p>
<p>The last feature currently on the roadmap is JMX support. Since Axon Framework deals with the dispatching and invocation of event handlers, it has interesting information about an application’s performance and technical state. We are planning to expose this information using JMX MBeans.</p>
<p>If you have any other ideas, you can submit a feature request on <a href="http://www.axonframework.org/issues" target="_blank">www.axonframework.org/issues</a>. </p>
<h2>Getting started with Axon</h2>
<p>If you&#8217;re eager to get started using Axon Framework for your own application, check out the <a href="http://www.axonframework.org" target="_blank">Axon Framework website</a>. There, you can download the binaries, sources documentation and a sample application. If you use Maven, the reference manual will explain how you can configure the dependencies on the Axon binaries.</p>
<p>If the information on the website is not enough to get you started, don’t hesitate to send me a message or post a comment at the bottom of this blog entry.</p>
<h2>A special thanks to…</h2>
<p>Before I wrap up, I would like to thank Jettro Coenradie for his help on the sample project and the reference documentation. I think the sample turned out into a pretty cool demo environment for some of the advantages that Axon can provide.</p>
<p>Also many thanks to <a href="http://www.jteam.nl" target="_blank">JTeam</a> for the time they allowed me to spend on the project. Without it, I am sure I couldn’t have delivered this release. Thanks!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jteam.nl/2010/02/21/axon-framework-the-cqrs-framework-for-java-version-0-4-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rethinking architecture with CQRS</title>
		<link>http://blog.jteam.nl/2009/12/21/rethinking-architecture-with-cqrs/</link>
		<comments>http://blog.jteam.nl/2009/12/21/rethinking-architecture-with-cqrs/#comments</comments>
		<pubDate>Mon, 21 Dec 2009 11:07:13 +0000</pubDate>
		<dc:creator>Allard Buijze</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Application Design]]></category>
		<category><![CDATA[Architecture]]></category>
		<category><![CDATA[CQRS]]></category>
		<category><![CDATA[Domain Driven Design]]></category>

		<guid isPermaLink="false">http://blog.jteam.nl/?p=1580</guid>
		<description><![CDATA[Many applications use some form of persistent storage to store its state. However, important information about this state is lost: why is the state as it currently is. Furthermore, a single model is used to store information that is retrieved for many different purposes, often resulting in extremely complex and bog-slow SQL queries. Command Query [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.jteam.nl/wp-content/uploads/2009/12/question_and_answer.png"><img style="margin: 5px 10px 0px 0px; display: inline; border-width: 0px;" title="question_and_answer" src="http://blog.jteam.nl/wp-content/uploads/2009/12/question_and_answer_thumb.png" border="0" alt="question_and_answer" width="64" height="64" align="left" /></a> Many applications use some form of persistent storage to store its state. However, important information about this state is lost: why is the state as it currently is. Furthermore, a single model is used to store information that is retrieved for many different purposes, often resulting in extremely complex and bog-slow SQL queries.</p>
<p>Command Query Responsibility Segregation (CQRS) is an architectural style that makes a clear distinction between commands that change the application state and queries that expose the application state.</p>
<p><span id="more-1580"></span></p>
<h2>Background</h2>
<p>My interest in CQRS was triggered when I saw Greg Young explain “<a href="http://www.infoq.com/interviews/greg-young-ddd" target="_blank">State Transitions in Domain-Driven Design</a>” on InfoQ. In this interview, Greg explains how he sees that application would benefit from using separate models for state validation and transition on one side and maintaining a view on the current state on the other.</p>
<p>One of the problems that Greg describes is the fact that a single model is often used for different purposes. It is nicely illustrated by the SQL query below. It shows how the model chosen in the application is not suited for the purpose of providing certain information (messages between users, in this case).</p>
<pre class="brush: java;">queryBuilder.append(
  &quot;m.*, &quot; +
  &quot;m.origin_participant_id as message_origin_participant_id, &quot; +
  &quot;po.first_name as message_origin_participant_first_name, &quot; +
  &quot;po.avatar as message_origin_participant_avatar, &quot; +
  &quot;po_ua.username as message_origin_participant_username, &quot; +
  &quot;CASE WHEN !isnull(po.fieldworker_project_id) THEN 'fieldworker' WHEN !isnull(po_ap.project_id) THEN 'fundraiser' ELSE 'player' END AS message_origin_participant_type, &quot; +
  &quot;po.city as message_origin_participant_city, &quot; +
  &quot;c.name as message_origin_participant_country, &quot; +
  &quot;pd.first_name as message_destination_participant_first_name, &quot; +
  &quot;pd.avatar as message_destination_participant_avatar, &quot; +
  &quot;pd_ua.username as message_destination_participant_username, &quot; +
  &quot;CASE WHEN !isnull(pd.fieldworker_project_id) THEN 'fieldworker' WHEN !isnull(pd_ap.project_id) THEN 'fundraiser' ELSE 'player' END AS message_destination_participant_type, &quot; +
  &quot;m.destination_participant_id as message_destination_participant_id &quot; +
  &quot;from internal_message m  &quot; +
  &quot;left join player po on m.origin_participant_id = po.id &quot; +
  &quot;left join (select player_id, project_id from ambassador_project where enabled = true group by player_id) po_ap on po_ap.player_id =  po.id &quot; +
  &quot;left join user_account po_ua on po.user_account_id = po_ua.id &quot; +
  &quot;left join country c on po.country_id = c.id &quot; +
  &quot;left join player pd on m.destination_participant_id = pd.id &quot; +
  &quot;left join (select player_id, project_id from ambassador_project where enabled = true group by player_id) pd_ap on pd_ap.player_id =  pd.id &quot; +
  &quot;inner join user_account pd_ua on pd.user_account_id = pd_ua.id &quot; +
  &quot;where m.destination_participant_id = ? &quot;
);
</pre>
<p>Wouldn’t it be a lot nice to have a query such as the one below instead?</p>
<pre class="brush: sql;">&lt;/pre&gt;
SELECT * FROM messages WHERE receiving_participant = ?
&lt;pre&gt;</pre>
<p>Achieving such queries is very easy, but doing so without making your model impossible to use for maintaining state integrity and guarding invariants is a lot harder. Well, unless you apply CQRS.</p>
<h2>Architecture</h2>
<p>The diagram below shows an overview of a typical CQRS architecture.</p>
<p><a href="http://blog.jteam.nl/wp-content/uploads/2009/12/cqrs_architecture.jpg"><img style="border-width: 0px; display: block; margin-left: auto; margin-right: auto;" title="cqrs_architecture" src="http://blog.jteam.nl/wp-content/uploads/2009/12/cqrs_architecture_thumb.jpg" border="0" alt="cqrs_architecture" width="404" height="281" /></a></p>
<p>When a command comes in, it will load an <a href="http://dddstepbystep.com/wikis/ddd/aggregate.aspx" target="_blank">aggregate</a> from the <a href="http://dddstepbystep.com/wikis/ddd/repository.aspx" target="_blank">repository</a> and execute certain operations on it. As a result of these operations, the aggregate produces events, which are picked up for storage by the repository and for dispatching by the event bus. The event bus will dispatch each event to all (interested) event handlers. Some of these event handlers will perform actions on other (related) aggregates, some others will update the database tables they manage.</p>
<p>Having handlers update the data in the database means that your tables do not have to be normalized anymore. Instead, CQRS allows you to optimize your tables for the way you want to query them. This makes the data layer processing your queries really simple, and maintainable.</p>
<p>Furthermore, since all state changes are initiated by events, these events become a reliable source for an audit trail. By storing these events, you have an audit trail that you can use to replay the entire application history. Instead of just seeing “current application state” only, you can see all the changes that have led to the current state, providing valuable information trying to find bugs or deal with customer complaints.</p>
<h2>Benefits</h2>
<p><strong>Matches the natural language used</strong></p>
<p>At first glance, such an architecture might look very complex and over-engineered. However, after taking the first implementation steps, it felt pretty natural. In fact, when you explain the behavior of an application, you use a style that fits CQRS quite nicely: “when an order is approved, we send a confirmation email to the customer”.</p>
<p><strong>Extensibility</strong></p>
<p>Imagine an order management application. With CQRS, you could have an “OrderApproved” event, which is caught by a database updating event handler as well as one that sends an email to the customer with order information. If you later on decide to store the order information in an accounting tool as well, all it takes is adding an event handler that does the accounting integration. And since you can reload historic events as well, you can even reconstruct historic information to put in the accounting table.</p>
<p><strong>Reliable audit trail</strong></p>
<p>As I said above [see section Architecture], the model that is used to process command will generate events. These events are the sole source of state changes for the domain classes. If you want to load an aggregate from persistent storage, it will actually load all the past events of that aggregate. This process is called Event Sourcing. When events become too numerous, you can combine a number of historic events into a single snapshot event. The events that have been combined can then be archived for auditing purposes.</p>
<p>Event Sourcing turns your event storage into an extremely reliable audit trail. The events do no only show what happened and when, but they will also reveal the intention a user had. Not only is it an audit trail that will never move out-of-sync with your application, you can use the audit trail to actually replay all actions in the application. Events are not just a notification of state change, they are also the source of state change.</p>
<p><strong>Transparent distributed processing</strong></p>
<p>When using events as the trigger for state changes, you can easily distribute your application over multiple processing units (servers, JVM’s, whatever). Events can easily be serialized and sent from one server to another over JMS, via the file system or even email. The Spring Integration framework –a messaging framework – fits nicely with the event processing concept.</p>
<p>You could even let certain types of aggregates live on dedicated machines. This allows you to choose different SLA’s for different parts of you application, such as giving order creation a higher priority than sales reporting.</p>
<p><strong>Performance and Scalability</strong></p>
<p>Since event handling is done asynchronously, a user does not have to wait for all changes to be applied. Especially when integrating with external systems, this can improve liveness of an application significantly.</p>
<p>Another aspect of CQRS is that it heavily builds upon BASE (<strong>B</strong>asic <strong>A</strong>vailability, <strong>S</strong>oft-state, <strong>E</strong>ventual consistency) transactions. Although the “eventual” part scares a lot of customers and developers, the price of distributed ACID transactions is one that customer typically resent. In most cases “eventual” is just a matter of several milliseconds. But you’re free to make that seconds, minutes or even hours if your SLA permits it (think of management reports that are only read once a week or month).</p>
<p><strong>Asynchronous analysis</strong></p>
<p>When you build a CQRS style application, all activity in your application is processed using events. This makes it easy to catch these events and monitor them for inconsistent behavior. Event analysis tools like <a href="http://esper.codehaus.org/" target="_blank">Esper</a> allow you to monitor event streams for patterns that indicate possible fraud.</p>
<p>For example, when you detect that a sudden large number of users has an increased amount of failed login attempts, you could decide to block these accounts for a small period of time. In one of our projects, we use <a href="http://www.rsa.com/node.aspx?id=3018" target="_blank">RSA Adaptive Authentication</a> to increase the level of authentication required when someone tries to login on an account that might be the subject of dictionary attacks.</p>
<h2>cqrs4j – an open source CQRS Framework</h2>
<p><a href="http://code.google.com/p/cqrs4j" target="_blank"><img style="display: inline; margin-left: 0px; margin-right: 0px; border-width: 0px;" title="cqrs4j logo" src="http://blog.jteam.nl/wp-content/uploads/2009/12/logo_large.png" border="0" alt="cqrs4j logo" width="100" height="100" align="left" /></a> A few days ago, I published the source code of a CQRS framework – <a href="http://code.google.com/p/cqrs4j" target="_blank">cqrs4j</a> – on Google code. This framework aims at reducing the amount of “plumbing” and boilerplate code to a minimum. It also provides integration support for Spring Integration and transactional event processing.</p>
<p>You can find project information, source code and documentation at <a href="http://code.google.com/p/cqrs4j/">http://code.google.com/p/cqrs4j/</a>.</p>
<p>[Update: cqrs4j has been renamed to Axon Framework. You can find more information on www.axonframework.org].</p>
<h2>Upcoming presentations and events</h2>
<p>JTeam organizes monthly Tech Meetings, where interesting technologies are discussed. The January 2010 edition will contain a presentation about CQRS. Registration is required, but free of charge. The tech meeting is held on January 7th in our office in Amsterdam [<a href="http://www.jteam.nl/contact.html" target="_blank">directions</a>] and starts at 16:00. It includes dinner.  Send us an <a href="mailto:techmeeting@jteam.nl?subject=I%20want%20to%20join%20the%203rd%20Dec%20Tech%20meet%20%40%20JTeam&amp;body=Name%3A%0AOrganization%3A%0Aemail%3A%0ATel.%23%0A" target="_blank">email</a> if you like to attend.</p>
<p>The DDDnl user group organizes a presentation and discussion session on March 9th, starting at 18:00. It is also held at the JTeam office in Amsterdam [<a href="http://www.jteam.nl/contact.html" target="_blank">directions</a>]. Attendance requires <a href="http://www.dddnl.org/user/register" target="_blank">registration</a> with the DDDnl user group, which is completely free of charge. Visit <a href="http://www.dddnl.org" target="_blank">dddnl.org</a> for more information.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jteam.nl/2009/12/21/rethinking-architecture-with-cqrs/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>DDD and modern software development</title>
		<link>http://blog.jteam.nl/2009/09/08/ddd-and-modern-software-development/</link>
		<comments>http://blog.jteam.nl/2009/09/08/ddd-and-modern-software-development/#comments</comments>
		<pubDate>Tue, 08 Sep 2009 15:07:09 +0000</pubDate>
		<dc:creator>Jettro Coenradie</dc:creator>
				<category><![CDATA[Business]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[DDD]]></category>
		<category><![CDATA[Domain Driven Design]]></category>

		<guid isPermaLink="false">http://blog.jteam.nl/?p=962</guid>
		<description><![CDATA[One of the main things we do @ jteam is creating rock solid custom development. Of course we use proven frameworks, we keep innovating and we use a lot of the best practices for custom software development. Best practices I am talking about are: Continuous Integration, Test Driven Development, Peer reviews and of course Scrum. [...]]]></description>
			<content:encoded><![CDATA[<p>One of the main things we do @ jteam is creating rock solid custom development. Of course we use proven frameworks, we keep innovating and we use a lot of the best practices for custom software development. Best practices I am talking about are: Continuous Integration, Test Driven Development, Peer reviews and of course Scrum. I guess I could use more buzz words in there, but that is not the scope for this item. So I am not going to talk about cloud, soa, virtualisation to name a few. This post is about why DDD is a match made in heaven with custom development.</p>
<p><span id="more-962"></span></p>
<h3>What is DDD?</h3>
<p>For those people reading this blog item and think: &#8220;<em>What is DDD?</em>&#8220;. DDD is an abbreviation for Domain Driven Design. We have been writing about DDD before on this blog: &#8220;<a href="/2009/05/10/the-misunderstanding-of-domain-driven-design/">The misunderstanding of domain driven design</a>&#8220;, &#8220;<a href="http://blog.jteam.nl/2009/07/28/domain-driven-design-applied/">Domain Driven Design applied</a>&#8220;.</p>
<p>The most important thing to know about DDD is the strong correlation between what the domain expert talks about in his normal working day, the design, the code and the tests. Even when talking about the project during a coffee break, the same language is used. This is what we call the <strong>Ubiquitous Language</strong>.</p>
<p>Another big part of DDD is creating the model. Since we are going to create a software solution for a problem in the domain, we need a form of simplification of that domain to base the solution on. This simplification is called the <strong>Model</strong>.</p>
<p>You have to know the <strong>context</strong> to understand the model. Some concepts of the domain can be important within one context, but not in another. Think about a cinema and a system to support buying a ticket. The ticket buying system needs the concept of a person buying a ticket. The seat allocation system does not need the person, just which seats are taken. Both systems deal with seats and people that want to watch a movie. Within the context of buying you need to have information about the person, within the context of seat allocation you don&#8217;t.</p>
<p>The central part of DDD is communication between the domain expert and the developers. The knowledge of the domain expert needs to be used while designing as well as coding a solution for the problem to be solved.</p>
<h3>What is custom development?</h3>
<p><img src="http://blog.jteam.nl/wp-content/uploads/2009/09/CE576EB1-08A2-409D-817B-94F3A8779D8B.jpg" border="0" alt="CE576EB1-08A2-409D-817B-94F3A8779D8B.jpg" width="200" height="201" align="left" />After this very brief introduction into what DDD is about and what the intentions are, let us discuss custom development. Custom development to me is everything more than having a product that needs to be configured and needs one or two adapters to make the product integrated with other systems. Custom development is about creating a new product. The product should be a perfect fit to the problem of the customer. Compare it to a closet you can buy at one of these big stores like the IKEA. Can be a nice closet, with some doors and drawers. It fits alongside the wall you have in mind, and it can be used for storing things. But you know your neighbor could have the exact same closet. The color could be off, the number of drawers is not exactly what you want. In short, it is not the closet you ever wished for. A solution to this problem could be to go to a carpenter and let him create the best closet you have ever seen. He asks what you want, what you want to use it for and how it must look. After a few months and a lot more money than that closet from the IKEA would have cost, you have the best closet ever.</p>
<p>Before the carpenter starts crafting your closet, he needs to know very well what you want. Often a sales person is between your idea and the carpenter. That sales person not know everything possible about the options that you might have. It could well be that the carpenter cannot create what you want. I personally have an experience in this area, we had a closet that was not what we asked for because the sales did not design the closet in a way the carpenter understood it. They also did not talk about it to verify if this was what I really wanted. More over, I did not talk to the carpenter to explain him what I wanted.</p>
<p>What does this have to do with creating fine software. A lot. When creating custom software you have to talk to the customer about what he wants. We, as software designers, must always talk to the domain expert to learn about the domain (what is the closet going to be used for). Of course this &#8220;<em>talk to the domain expert</em>&#8221; is also true for package based solutions. The freedom that you have related to custom development is much smaller.</p>
<p>So what is important for a good, custom developed, solution? Of course you need a lot of common best practices like: Continuous Integration, Test Driven Development, Quality control, pair programming and JTeam (sorry could not resist). In itself none of these practices will give the customer what he wants. You need to combine these practices with a good process.  At JTeam we strongly believe in light weight agile processes. Our own projects are executed using scrum. To be sure you create the best solution, give the customer a lot of feedback moments. We always work iteratively, or within scrum terms, in sprints.</p>
<p>The final step in creating well developed custom software, is to actually understand what the customer wants, and build exactly that. Wouldn&#8217;t it be nice if the customer could actually read the code and help the developers to make it better? Of course it would be nice. The solution to that problem should be obvious by now. We use Domain Driven Design to make that happen. Therefore DDD is not the best thing that a developer can learn, it is the best thing that can happen to the customer. That carpenter would have created a much better closet if he would have consulted the domain expert of his customer. My wife knows very well what she wants to use those drawers for. (In reality most of the stuff in the drawers is from me, but this does make the example better <img src='http://blog.jteam.nl/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  ). If the carpenter would have talked to my wife, we would have a better closet and he would not have given us a discount. He could also have sent us some pictures while he was working on the closet. To give feedback about what you are creating is very important to come with the right custom built solution.</p>
<h3>DDD together with Agile practices</h3>
<p><img title="A scrum in rugby" src="http://blog.jteam.nl/wp-content/uploads/2009/09/9309B773-A867-438E-8DDC-B1DD6A782C4E.jpg" border="0" alt="9309B773-A867-438E-8DDC-B1DD6A782C4E.jpg" width="194" height="300" align="right" />I am not going to heavily describe what Agile is about. There are so many resources about being agile that I invite you to <a href="http://www.google.com/search?q=agile+software+development">use google</a> to find out more about it. Within JTeam we prefer to use Scrum for our projects. We like doing sprints, work with a backlog of items to be done. Just like with DDD, Scrum needs a good involvement of product owners to make it a success. Scrum has the goal to deliver working software every sprint. That is only possible when making small steps. Just like DDD, Scrum works with stories. DDD uses stories to create and verify the model. Scrum uses stories to determine the scope for each sprint, write tests and running software. Both DDD and Scrum use tests to verify if everything works. Scrum uses tests to verify if the story is implemented, DDD uses tests to create a good API. Both prefer to write the tests before the actual code.</p>
<p>To me, agile practices like those from Scrum, strengthen the DDD offering. Together they give the customer what he really wants. If something goes wrong, you notice at least after each sprint. Using the domain expert, the risks for doing something completely wrong are little. Be sure to make it possible to make mistakes. Especially in big custom developed systems, you need to be able to make mistakes to create the best possible solution. Refactoring is part of the agile practices, use it to make the design and code a better reflection of the domain.</p>
<h3>Why is DDD the best thing for a customer?</h3>
<p>By now you should have a basic idea why DDD is the best thing for a customer to happen in his project. The customer gets a custom made software solution that tackles the biggest problem of his business. Because DDD is such a nice fit with Agile practices, he will have a lot of influence on the process as well as the end product. One thing that I learned by experience is that using DDD, the domain expert can help improve software and to understand what has been created. Let me explain what I mean by an example.</p>
<p><a href="http://www.primatras.nl"><img src="http://blog.jteam.nl/wp-content/uploads/2009/09/primatras_logo.png" border="0" alt="primatras_logo.png" width="172" height="40" align="left" /></a>For a friend of mine I am creating a backoffice system for his online store. This backoffice has been in production for quite a few years now. We keep on extending it and every now and than we need to make changes to functionality I have created years ago. Since I am not the perfect programmer (who is?), there are some pieces in the software that are not documented well enough, do not have enough unit tests and are just not clear code. When I started to create the backoffice I did not use DDD. Not all terms I used in the code were the same as my friend uses in his day to day business. When I had to make a change in the workflow of the order, we had a very hard time trying to find out what the process actually was and relate that back to the code. Of course my friend knows exactly how he runs his business, but that was not reflected in the code. So he could not help me to explain what the code does. If I had been closer to the domain in the code, he could have explained me very well what the code has been doing.</p>
<p>To me that is the most important aspect of DDD, make sure that the design and code are based on the domain in a way that the domain expert can help you understand the code. Of course that should not be a reason not to document the code or write crappy code. Since he can only explain the concepts.</p>
<h3>What do we need from a customer to make DDD a success?</h3>
<p>There are a few things you as a customer must take care of in order to make this DDD thing a success.</p>
<ul>
<li>Work with an iterative process, we prefer Scrum.</li>
<li>Make the domain expert(s) available to the team, preferably face to face, during the complete project.</li>
<li>Provide a domain expert who can make decisions, not someone who has just started and needs to ask everything himself.</li>
<li>Make the project a shared effort, preferably not fixed time and fixed budget. Try to come into an environment of trust between customer and supplier where each sprint should be a moment of evaluation of the relationship.</li>
</ul>
<h3>What are the next steps?</h3>
<p>Ok, you have read this article. (<em>warning: start commercial part</em>)If you want to learn more, feel free to give us a call. We love to do custom development and we are good at it. We can show you what we have done. One of the things we like to do is have an open discussion with your domain experts to talk about their problems that need to be solved. (<em>end commercial part</em>)</p>
<p><img src="http://blog.jteam.nl/wp-content/uploads/2009/09/dddnl_logo.png" border="0" alt="dddnl_logo.png" width="152" height="95" align="left" />Because we really believe in Domain Driven Design, we have started a user group in the Netherlands. We are looking for members that want to learn more about DDD and/or share their experience with DDD. Have a look at <a href="http://www.dddnl.org">http://www.dddnl.org</a>. We are planning to organize events in the future, if yo have ideas let us know.</p>
<p>There are a lot of other resources to learn about DDD, you can start with the following website.</p>
<ul>
<li><a href="http://www.domaindrivendesign.org/">http://www.domaindrivendesign.org/</a> &#8211; Home page of the DDD community.</li>
<li><a href="http://www.dddnl.org">http://www.dddnl.org</a> &#8211; Dutch DDD user group</li>
<li><a href="http://en.wikipedia.org/wiki/Domain-driven_design">http://en.wikipedia.org/wiki/Domain-driven_design</a> &#8211; Home page on wikipedia with a lot of links to other resources.</li>
</ul>
<p>Hope you like the article, feedback is very welcome.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jteam.nl/2009/09/08/ddd-and-modern-software-development/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>JTeam Technology Matrix: The Stars</title>
		<link>http://blog.jteam.nl/2009/09/07/jteam-technology-matrix-the-stars/</link>
		<comments>http://blog.jteam.nl/2009/09/07/jteam-technology-matrix-the-stars/#comments</comments>
		<pubDate>Mon, 07 Sep 2009 10:30:07 +0000</pubDate>
		<dc:creator>Bram Smeets</dc:creator>
				<category><![CDATA[Business]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Amazon Web Services]]></category>
		<category><![CDATA[DDD]]></category>
		<category><![CDATA[Domain Driven Design]]></category>
		<category><![CDATA[Google Web Toolkit]]></category>
		<category><![CDATA[GWT]]></category>
		<category><![CDATA[Innovation]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Mockito]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[Scrum]]></category>
		<category><![CDATA[Solr]]></category>
		<category><![CDATA[Technology Matrix]]></category>
		<category><![CDATA[Wicket]]></category>

		<guid isPermaLink="false">http://blog.jteam.nl/?p=797</guid>
		<description><![CDATA[In Alef&#8217;s previous blog entry about the JTeam Technology Matrix, he explained the basic idea of using a BCG-matrix to classify technologies. In this blog entry I&#8217;ll focus on the &#8216;Star&#8217; section of our current matrix and highlight some of the technologies that are currently in there. Star technologies are the technologies that bring us [...]]]></description>
			<content:encoded><![CDATA[<p>In Alef&#8217;s previous blog entry about the <a href="/2009/04/16/the-bcg-matrix-at-jteam-new-cool-technologies/">JTeam Technology Matrix</a>, he explained the basic idea of using a BCG-matrix to classify technologies. In this blog entry I&#8217;ll focus on the &#8216;Star&#8217; section of our current matrix and highlight some of the technologies that are currently in there. Star technologies are the technologies that bring us added value in the projects that we do, but are also cool and innovative to use. Please keep in mind that the content of the matrix is under constant discussion and is subject to change. This overview should therefore be considered a snapshot of today&#8217;s matrix.<br />
<span id="more-797"></span></p>
<h2>The Stars</h2>
<p>Our current physical technology matrix lists the following technologies (in alphabetical order):</p>
<h3>Amazon Web Services (AWS)</h3>
<p>Amazon Web Services is a collection of web services offered over the internet by amazon.com. The most noteworthy services are:</p>
<ul>
<li>Amazon S3 &#8211; Cost effective way to redundantly store large amounts of data</li>
<li>Amazon EC2 &#8211; Start / stop virtual private servers on demand via a webservice interface and pay only for the computing power you use</li>
</ul>
<p>We think it makes sense to use S3 if it fits your needs, it is particularly well suited for backup solutions.</p>
<p>Traditional EC2 uses have been hosting temporary (non critical) infrastructure or performing computationally intensive tasks. For these use cases EC2 is very well suited. As of recently you can assign a server a static IP address and have the ability to persist data through server restarts. This makes EC2 a more attractive choice to consider for hosting a production site. The webservice interface that AWS provides allows you to build a true cloud infrastructure on top of EC2 (e.g. start up another server if the load reaches a certain threshold and stop that server again when the load goes down).</p>
<p>We at JTeam use S3 for our internal and customer backups. Furthermore we use EC2 to host some of our project infrastructure like ScrumWorks, TeamCity, Artifactory and the like. We also use EC2 to host UAT environments for our customers. So far we have not used it to host production environments on it.</p>
<h3>Domain Driven Design (DDD)</h3>
<p>DDD is not a technology or a methodology. It is a way of thinking and a set of design practices, techniques and principles aimed at accelerating software projects. DDD was pioneered by Eric Evans in his book <a href="http://www.amazon.com/Domain-Driven-Design-Tackling-Complexity-Software/dp/0321125215">Domain-Driven Design</a>.</p>
<p>In our opinion DDD is a good way to professionalize the contact with our client / domain expert. It also allows us to shows the benefit of using DDD directly to the client. DDD really fits our way of working (e.g. Agile, close customer contact and fixed budget), because it provides an easy bridge between the customer requirements and the code. It allows the client to almost read the code as it is delivered. Because of this readability, it also is much better fitted to testing and documenting user stories.</p>
<h3>Google Web Toolkit (GWT)</h3>
<p>GWT is our preferred way to develop advanced RIAs (assuming certain prerequisites like no requirements related to SEO). We use it for developing backend / administrative interfaces in an intuitive manner. The main reason why we prefer to use GWT is that it allows us to build Swing like / fat client applications that run in any web browser. For users, this means no need to install software to run the application, while still getting an intuitive UI. Of course there are several ways to develop RIAs, but GWT has our preference because it allows us to write applications in our preferred language: Java. The added value of this is that we can reuse all of our tools and best practices (e.g. IDE, build environment and TDD).</p>
<p>We have been using GWT for some time now and even wrote a <a href="http://www.amazon.com/Beginning-Google-Web-Toolkit-Professional/dp/1430210311">book</a> about it. However, we feel GWT is still innovative and cool, as new features are added with every release and there is still a lot of innovation to do there. Therefore, it is definitely a star technology.</p>
<h3>GwToolbox</h3>
<p>GWT is a great technology to develop advanced RIA. Anyone experienced with Swing (or GWT) knows that this programing model can act as a double edge sword &#8211; on one hand, it is simple and intuitive for Java developers for developing UIs, but on the other hand, when not following adequate design patterns and programming paradigms, even a relatively simple GWT application code base can quickly become messy and unmaintainable. The main goal of GWToolbox is to define best practices and design pattern that aid in developing clean and modular GWT applications. GWToolbox contains 3 main modules:</p>
<ul>
<li><strong>IoC</strong>: Using simple yet powerful dependency injection, one can maintain a clean code base even for the most complex applications. But DI is not enough &#8211; the framework promotes event driven development to the max by providing an infrastructure for application level events. This greatly simplifies the interaction between the different modules/component of the application.</li>
<li><strong>SpringRpc</strong>: This module provide simple support classes to integrate a GWT application with the Spring Framework. Although there are several such integration libraries out there, this module tries to make full use of the latest features in Spring. It uses the component scanning mechanism to pick up services in the application context that should be exposed to the GWT client application. In addition, custom namespaces are defined which simplify development even more.</li>
<li><strong>Widget</strong>: The widget module contains different kind of widgets that can be used to create advance RIAs. There are many widgets out there already, but they are either GPL licensed or not as advance as you typically need.</li>
</ul>
<h3>jQuery</h3>
<p>jQuery is just one of those libraries you can&#8217;t live without when creating a Web 2.0 website with plain old HTML and Javascript. It is a Javascript library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. Not only that, but it <em>teaches</em> you to write maintainable Javascript code. With a little effort you can do amazing visual things on your website, all the while keeping the code readable and concise. So next to pleasing your customer by creating cool things with jQuery, it actually provides lot of added value to you as a developer too. I can see jQuery play an important role in Web 2.0 development for the upcoming years, but it may have to give ground to the more RIA-oriented technologies like GWT and Flex.</p>
<h3>Mockito</h3>
<p>Mockito is innovative because it represents the state-of-the-art in Java mocking frameworks. It has taken the best practices and the best ideas pioneered by previous mocking frameworks, and applied these in the best way possible. It allows unit tests to be both more expressive and easier to read. In comparison, EasyMock &#8211; another currently popular mocking framework &#8211; tends to produce more over-specification, resulting in more brittle tests. Finally Mockito&#8217;s idiom is both simple and consistent, making mocking easier to learn for TDD newbies.</p>
<p>As a result, Mockito adds value to our business by helping us make our code more robust and easier to maintain and evolve. In the coming years we expect Mockito to become mainstream, and succeed EasyMock as the de-facto standard Java mocking solution.</p>
<p>Rob van Maris&#8217; blog post titled <a href="http://blog.jteam.nl/2009/08/13/easier-mocking-with-mockito/">Easier mocking with Mockito</a> describes how to use Mockito and how it compares to EasyMock.</p>
<h3>Scrum</h3>
<p>Agile software development is a combination of technical, social and organizational aspects. It requires a matching set of engineering and project management practices. This is where Scrum fits in.<br />
Scrum is a lightweight framework for project management that promotes the Agile Principles. It complements our engineering practices and promotes the same core values (organizational learning, quality, personal development, fun). We have applied Scrum in various projects and like the way it contributes to success factors like transparency, customer involvement, focus, productivity, motivation and self-improvement. On the other hand, Scrum has introduced new challenges regarding how we sell projects and services, how we manage projects and how we manage resources.<br />
There is currenlty a lot of hype surrounding Scrum, and many seem to regard it as a silver bullet. Someday the hype will be over, but by then Agile software development will have become (almost) mainstream.</p>
<h3>Solr</h3>
<p>Solr is definitely one of the biggest stars (if not *the* biggest). Solr is a Lucene based search server which makes enterprise search available as a service. Not only does it bring together all Lucene/search best practices in one box, but it also extends on Lucene&#8217;s basic search functionality with powerful features like faceted classification, statistics, and a powerful and extensible query language. Due to an open and extensible architecture, it is very easy to extend Solr with even more functionality (for example, there&#8217;s already an extension which integrates document clustering functionality to search results). Ok, so it&#8217;s a powerful search server, but why is it a star? Simply because search is growing big&#8230; very big. In the last 2-3 years we&#8217;ve witnessed it first hand from our clients. Perhaps it&#8217;s the Web 2.0 era, or maybe its the proliferation of information that has grown too big to handle, but more and more companies realize that their products cannot do without a good powerful search functionality. We can honestly say that in the last 2 years more than 85% of the projects we did had some form of search integration requirement, most of which grew with time with features and functionality. Today, Solr (and search in general) sells itself. Solr already started to gain good reputation and if 2 years ago we had to explain companies what Solr is and what it can do for them, today customer already know that Solr is what they want and come to us for our Solr expertise.</p>
<h3>Wicket</h3>
<p>Wicket is a Java framework for web applications. A big difference compared to many other web frameworks is that it does not require a special language (e.g. JSP), just Java and HTML. Furthermore, Wicket is component oriented. Each component is responsible for only a small piece of a web page. Components are reusable which allows you draw from an extensive collection of existing components. These components come from Wicket itself, but also from the open source community. Of course it is possible to build your own collection. This way of working leads, even for very complicated screens, to highly maintainable applications.</p>
<p>Almost every sentence in the paragraph above indicates why Wicket is cool, innovative and productive. Wicket is actively supported and developed and is therefore an excellent choice into the future.</p>
<h2>What is next?</h2>
<p>I hope this blog entry gives you some insight into the technologies / methodologies that we at JTeam feel are interesting both from an innovation perspective as well as from an added value perspective. As mentioned before, maintaining this matrix is an ongoing effort, therefore this list is subject to change.<br />
In the future you can expect updates as well as blog posts about the other parts of the technology matrix (which will lead to a lot more controversy <img src='http://blog.jteam.nl/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> ).</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jteam.nl/2009/09/07/jteam-technology-matrix-the-stars/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Domain Driven Design applied</title>
		<link>http://blog.jteam.nl/2009/07/28/domain-driven-design-applied/</link>
		<comments>http://blog.jteam.nl/2009/07/28/domain-driven-design-applied/#comments</comments>
		<pubDate>Tue, 28 Jul 2009 14:27:53 +0000</pubDate>
		<dc:creator>Allard Buijze</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Domain Driven Design]]></category>
		<category><![CDATA[Productivity]]></category>
		<category><![CDATA[Project]]></category>

		<guid isPermaLink="false">http://blog.jteam.nl/?p=598</guid>
		<description><![CDATA[In a recent project for Osix, we developed an application allowing visitors of a library to use the wireless Internet connection available there. Visitors can pay for the Internet access in two ways: an online payment, for example using a credit card or by deducting the amount from their library account. All user accounts, as [...]]]></description>
			<content:encoded><![CDATA[<p>In a recent project for <a href="http://www.osix.nl" target="_blank">Osix</a>, we developed an application allowing visitors of a library to use the wireless Internet connection available there. Visitors can pay for the Internet access in two ways: an online payment, for example using a credit card or by deducting the amount from their library account. All user accounts, as well as the available products, library configurations and payments are managed from a single central application, called Digital Services Manager.</p>
<p>In this post, I will elaborate on how <a href="http://domaindrivendesign.org/" target="_blank">Domain Driven Design</a> has helped us build a clean and maintainable application, mainly focusing on some technical and implementation choices that we have made.</p>
<p> <span id="more-598"></span>
</p>
<h3>DDD Background</h3>
<p>Domain Driven Design is really about the way software is developed. Hence, it will say more about the way to get to an implementation than about the actual implementation itself. However, if you do it correctly, you will find some of the DDD principles back in your implementation.</p>
<p>The most important concept in DDD is the “Ubiquitous Language”: the language that is used within the domain by all people involved, such as domain expert (our customer), developers and stakeholders. Since this language is used by everybody, it is best to reflect that language directly –hence without translation– in your code. Since the language will contain both nouns and verbs, this means that you will end up with a <a href="http://martinfowler.com/eaaCatalog/domainModel.html" target="_blank">Rich Domain Model</a>.</p>
<p>Another really important principle of DDD is “make it explicit”. I can’t even recall how many times Eric Evans said that during the four day training he gave two weeks ago. This means that, for example, every time you come across some relationship between two values, you should assemble these two values and name the combination. This way, you make the relationship between these values explicit and named. This name should either come from the Ubiquitous Language or should be introduced as part of it. Yes, that means no single developer can make up a name for something without consulting the domain expert first.</p>
<h3>How this reflects in the implementation</h3>
<p>Most people I talk to are curious about how this reflects in the implementation. Some people even seem to reject DDD because it is not really all that different in the implementation. Of course it isn’t, at least, not on first sight.</p>
<p>In the OSIX domain, people can use wireless access points in Libraries to gain access to the Internet using their laptop. To do this, they need to register themselves in a central application, owned and maintained by OSIX. This application serves as a web shop where users can buy credits, it provides administrators to block or enable users and keeps a log of actual time spent online.</p>
<p>This means our domain model implementation contains classes like Library, User and InternetSession. This last one is DDD-implementation wise quite interesting.</p>
<p>We needed to log the time a user logged on and when he logged off again. Hence, our first name for this class was “LogEntry”. Technically, we are just talking about a giant Log with a lot of entries. However, DDD requires that everything is to be made explicit and named according to the Ubiquitous Language. So, we consulted the domain expert. He said he calls it Internet Sessions. A user starts an internet session, and an internet session is ended when a user logs of.</p>
<p>Does it change the implementation of the class much? Not really, except for some different method names, perhaps, nothing is really different. In the end, we’re still programming Java, and the same things need to be done. And if you’re used to Anemic Domain Models, you’ll probably have to get used to the fact that invariants are guarded inside the domain object itself, instead of a service.</p>
<p>So, why is this naming important? First of all, it allows your developers and domain expert to talk the same language, without the need of continuous translation. Secondly, new developers joining the project will easily pick up the language and recognize the concepts in the code. This really showed when we needed to change some developers. The new developer was quickly able to see which functionality had been implemented and which still needed some work. Finally, our client, who has a fair understanding of the Java language, was able to understand our implementation and give us direct feedback.</p>
<h3>How about persistence?</h3>
<p>Somehow, many people see Domain Driven Design and Rich Domain Model as the same thing. It’s simply not true. A Rich Domain Model is the logical consequence of a DDD project, since everything is made explicit. And making things explicit means providing names, properties and behavior to concepts.</p>
<p>Another assumption often made is that Rich Domain Model means “put all logic in the domain”. Which is also not true. It’s not called a model for nothing. Using a model means you consciously leave things out of your domain, because they are either not relevant or not practical in your implementation.</p>
<p>In the OSIX project, we assigned the responsibility of retrieving and persisting objects to the application layer. This means the application services call on the Repository implementations to retrieve or save objects.</p>
<p>Furthermore, we decided to keep all modifications to the state of Entities inside the scope of the Application Layer. In the implementation, this meant two things. First of all, the Transactional boundary is located on the service layer, meaning that entities leaving the Application Service are detached from the persistence context, meaning that changes will not be seen by the persistence manager and are ignored. Secondly, the service layer will never accept an entity as a parameter. If an entity is needed, the application service will retrieve it based on its identity, which is passed as a parameter instead.</p>
<p>Some of the Application Service interfaces methods look as follows:</p>
<pre>
<pre class="brush: java;">
InternetSession startSession(final LocalDateTime startTime,
                             final UserName userName,
                             final BranchCode branchCode,
                             final IpAddress ipAddress);

void endSession(final long id,
                final LocalDateTime endTime,
                final BranchCode branchCode);
</pre>
</pre>
<p>All method parameters are value objects, and thus immutable, thread safe and the whole shebang. The startSession method returns en entity: InternetSession. If you wish to change the state of that object in a way that is useful to the application, you need to call another method (e.g. endSession) using the identity of the session, a long in this case. (Yes, in the case of “make it explicit”, SessionId would be a better name for it.)</p>
<p>The implementation of this application service is no rocket science either. It contains only little logic, since it delegates most of it to the domain objects themselves.</p>
<pre>
<pre class="brush: java;">
@Transactional
public void endSession(final long id,
                       final LocalDateTime endTime,
                       final BranchCode branchCode)
               throws NoSuchSessionException {

    InternetSession session = internetSessionRepository.loadSession(id);
    if (!session.getBranchCode().equals(branchCode)) {
        throw new NoSuchSessionException(&amp;amp;quot;This session belongs to another Branch&amp;amp;quot;);
    }

    if (session.isOpen()) {
        session.closeSession(endTime);
        internetSessionRepository.saveSession(session);
    }
}
</pre>
</pre>
<p>Line 7 shows the actual InternetSession entity being retrieved from the repository. In Hibernate/JPA terms this means the entity is attached to the PersistenceContext, and all changes are observed by the persistence manager.</p>
<p>Line 8-10 show some very simple validation logic to prevent sessions from another Branch being closed accidentally.</p>
<p>Line 12-14 do the calls to the actual business logic involving the closing of a session.</p>
<p>You could state that the Application Service is responsible of the orchestration of business logic execution. It doesn’t say anything about what the business logic actually means (e.g. what does it it mean that a session is open?).</p>
<h3>Conclusion</h3>
<p>In the end, DDD doesn’t really drastically change the way most applications are built. The most important change is the actual naming of objects and methods and the location of the business logic. However, this seemingly subtle change can have a big effect on the maintainability of your application.</p>
<p>Domain Driven Design is mainly about making things explicit, and doing so in the Ubiquitous Language.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jteam.nl/2009/07/28/domain-driven-design-applied/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>The misunderstanding of Domain Driven Design</title>
		<link>http://blog.jteam.nl/2009/05/10/the-misunderstanding-of-domain-driven-design/</link>
		<comments>http://blog.jteam.nl/2009/05/10/the-misunderstanding-of-domain-driven-design/#comments</comments>
		<pubDate>Sun, 10 May 2009 15:11:04 +0000</pubDate>
		<dc:creator>Allard Buijze</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Domain Driven Design]]></category>

		<guid isPermaLink="false">http://blog.jteam.nl/2009/05/10/the-misunderstanding-of-domain-driven-design/</guid>
		<description><![CDATA[There seem to be two mainstream approaches in Java application development: the domain driven approach, and the “fat service layer” or Transaction Script approach. As an architect, I’ve been investigating both methodologies by reading about both of them and applying them in real life enterprise projects. It is at the least amusing to see how [...]]]></description>
			<content:encoded><![CDATA[<p>There seem to be two mainstream approaches in Java application development: the domain driven approach, and the “fat service layer” or <a href="http://martinfowler.com/eaaCatalog/transactionScript.html" target="_blank">Transaction Script</a> approach. As an architect, I’ve been investigating both methodologies by reading about both of them and applying them in real life enterprise projects. It is at the least amusing to see how followers of each approach think of the other. An example of how developers (disappointing to realize that these people are co-developers) react on each other&#8217;s approach can be seen in the <a href="http://www.theserverside.com/news/thread.tss?thread_id=42602" target="_blank">reactions to Arjen Poutsma’s post</a>.</p>
<p><span id="more-115"></span></p>
<p>In some discussions I recently had with developers as well as other architects, I noticed that Domain Driven Design and Rich Domain Model  are interpreted as “put <em>everything</em> in the domain model”. This means (according to some of them) that each object should have a “save” method to persist its state, external systems calls are initiated by the domain objects, and so on and so forth. I have to agree with them that such an approach would not be practical at all. All it would lead to is bloated domain objects of which the real purpose is hidden in hundreds of lines of boilerplate code. However, I don’t believe that Domain Driven Design is about any of this at all. And looking at Eric Evans’ (the writer of the book Domain Driven Design) <a href="http://domaindrivendesign.org/examples#sampleApp" target="_blank">sample application</a>, my thoughts are confirmed.</p>
<p>Domain Driven Design is an approach that describes the approach to designing the business layer. It doesn’t say much about the other layers of an application. The main advice is to base the domain model on the language your customer uses: the ubiquitous language. This means that you should not have a method “setAddress” on a Customer instance if your customer talks about “register a relocation”. In fact, the last application I developed hardly contained any setter on any domain instance at all.</p>
<p>You might wonder what happened to the other layers if DDD is really only about the business layers. Well, the service layer is still what it was, although it tends to contain less code. All that is needed in the service layer is to retrieve the correct domain instance(s) from the repository, call the appropriate methods on them and persist their new state by placing them back in the repository. With this approach, the logic of changing the state is located where the state is kept, in the domain object. The application logic, such as persistence, transactions, calling external application, raising application events, is placed in the service layer.</p>
<p>During one of my discussions, somebody pointed out that according to the Domain Driven Design book one should only create a service if the logic cannot be placed in any of the domain objects. Well, the book does say that, but the service the book talks about is not the type of service that you find in the service layer. The book talks about Domain Services. Whether you decide to use one of these services is completely independent of the use of services in the service layer, which are also referred to as application services.</p>
<p>I can conclude that applications where domain driven design has been applied are not really that different from other applications, with the exception of the domain model itself. However, this richer model tends to make applications more maintainable and easier to understand as the model exposes the language that the customer actually uses. So, in the end, Domain Driven Design does not have to be as scary as many people think. It is just, as one of my colleagues pointed out, a set of best practices for Object Oriented design.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jteam.nl/2009/05/10/the-misunderstanding-of-domain-driven-design/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
