<?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>Gridshore &#187; DDD</title>
	<atom:link href="http://www.gridshore.nl/category/ddd/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.gridshore.nl</link>
	<description>A weblog about software engineering, Architecture, Technology an other things we like.</description>
	<lastBuildDate>Tue, 13 Dec 2011 15:36:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Coming up in the Axon Framework</title>
		<link>http://www.gridshore.nl/2011/05/11/coming-up-in-the-axon-framework/</link>
		<comments>http://www.gridshore.nl/2011/05/11/coming-up-in-the-axon-framework/#comments</comments>
		<pubDate>Wed, 11 May 2011 09:02:32 +0000</pubDate>
		<dc:creator>Allard</dc:creator>
				<category><![CDATA[Axon Framework]]></category>
		<category><![CDATA[DDD]]></category>
		<category><![CDATA[Domain Driven Design]]></category>
		<category><![CDATA[test driven development]]></category>

		<guid isPermaLink="false">http://www.gridshore.nl/2011/05/11/coming-up-in-the-axon-framework/</guid>
		<description><![CDATA[<p>Recently, I released Axon Framework 1.0. Instead of it being an opportunity to take a small break, things have gone into a higher gear instead. In this article, I give a sneak preview of what’s coming up in and around Axon Framework.</p> <p> More test fixtures <p>Testing is obviously very important. Axon already has [...]]]></description>
			<content:encoded><![CDATA[<p>Recently, I released Axon Framework 1.0. Instead of it being an opportunity to take a small break, things have gone into a higher gear instead. In this article, I give a sneak preview of what’s coming up in and around Axon Framework.</p>
<p><span id="more-1153"></span><br />
<h2>More test fixtures</h2>
<p>Testing is obviously very important. Axon already has test fixtures to test your command handling components using an easy-to-use given-when-then fixture. But the command handling component is not the only component with potentially complex business logic.</p>
<p>Axon 1.1 will include a similar fixture for testing Sagas. The big difference between a Command Handler and a Saga is that the Saga responds to Events and takes decisions based on them. Quite often, the aspect of time is important. For example, if an invoice is not paid within 30 days, the Saga must send a command to cancel or block an Order. The Saga test fixture allows you to write code like this:</p>
<pre>
<pre class="brush: java; title: ; notranslate">fixture.givenAggregate(orderAggregate).published(new OrderCreatedEvent())
       .andThenAggregate(invoice).published(new InvoiceSentEvent())

       .whenTimeElapses(Duration.standardDays(31))

       .expectDispatchedCommands(new BlockOrderCommand());
</pre>
</pre>
<p>This allows you to write human-readable test that define what the behavior should be when certain things happen, or even when they don’t happen.</p>
<p>Work on these fixture is still in progress, but a sneak preview is available in the 1.1-SHAPSHOT version already. Look for the AnnotatedSagaTestFixture class, give it the class you want to test and you are ready to start testing.</p>
<h2>Redis event store</h2>
<p>Redis is a very nice and full-featured key-value store. Instead of values being plain blobs, Redis allows for lists, sets, maps (called hashes) and even ordered sets. There is also a pub/sub mechanism in place and the API supports the implementation of message queues.</p>
<p>All in all, this makes Redis a very nice candidate for an Event Store implementation. We have already spent some time investigating the API and the level of consistency guarantees that Redis can offer. They match very well with what one would expect from an Event Store. We’ll be spending some more time on it before we decide whether to implement a full-blown Event Store, or not.</p>
<h2>Distributed command bus</h2>
<p>Scalability is obviously one of the reasons to choose for CQRS. Having components that only work within a single JVM doesn’t really help. I have done a small proof-of-concept with a Distributed version of the Command Bus. So far, the results look really good.</p>
<p>This Command Bus implementation allows commands to be distributed over a cluster of machines for execution. Instead of blindly sending commands to random machines, it uses the Consistent Hashing algorithm to make sure that commands for the same Aggregate will end up on the same machine. If a machine drops, the load is taken over by the remaining machines. You can even –at runtime- add another machine to the cluster and have it take over some of the load. This means you can dynamically adapt your cluster size to meet the needs of that specific moment, without any single-point-of-failure.</p>
<p>The distributed command bus is still in the proof-of-concept phase, but work on the real version will start very soon. I will also build a small application that allows you to see it at work.</p>
<h2>2-day “full-immersion” training</h2>
<p>Spreading knowledge on CQRS and the Axon Framework has always been on the agenda. In the past few months, I have given suite a number of presentations and 1-day workshops. Although they are nice to do, there is too little time to really dive into the matter. That’s why I have decided to go for a 2-day training.</p>
<p>This two day training is a little different that what you’re used to. Instead of doing a training over 2 days from 9AM to 5PM, this training is 32 hours in a row. Okay, admitted, this includes a few hours of eating and sleeping as well. The training takes place in a hotel in the beautiful “Utrechse Heuvelrug” area in The Netherlands. It’s 2 days, all-in (overnight stay and meals). The idea behind this concept is that we’ll be able to really dive deep into the concepts and get to the bottom of things. So after dinner on the first day, there is time for coding as well as informal chatting at the hotel bar.</p>
<p>The training covers the basic concepts of DDD and CQRS, but also allows you to really get your hands dirty. The first training has been scheduled for June 23rd and 24th 2011. For more information about this training, visit the training page: <a href="http://www.jteam.nl/training/workshop/2-day-CQRS-and-Axon-Immersion-Training.html">http://www.jteam.nl/training/workshop/2-day-CQRS-and-Axon-Immersion-Training.html</a>.</p>
<div class='dd_post_share'><div class='dd_buttons'><div class='dd_button'><iframe src='http://widgets.dzone.com/links/widgets/zoneit.html?url=http%3A%2F%2Fwww.gridshore.nl%2F2011%2F05%2F11%2Fcoming-up-in-the-axon-framework%2F&amp;title=Coming%20up%20in%20the%20Axon%20Framework&amp;t=2' height='25' width='155' frameborder='0' scrolling='no'></iframe></div></div><div style='clear:both'></div></div><!-- Social Buttons Generated by Digg Digg plugin v4.5.3.4, 
    Author : Yong Mook Kim
    Website : http://www.diggdigg2u.com -->]]></content:encoded>
			<wfw:commentRss>http://www.gridshore.nl/2011/05/11/coming-up-in-the-axon-framework/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Axon Framework 0.6 released</title>
		<link>http://www.gridshore.nl/2010/08/08/axon-framework-0-6-released/</link>
		<comments>http://www.gridshore.nl/2010/08/08/axon-framework-0-6-released/#comments</comments>
		<pubDate>Sun, 08 Aug 2010 17:53:45 +0000</pubDate>
		<dc:creator>Allard</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Axon Framework]]></category>
		<category><![CDATA[DDD]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[cqrs]]></category>
		<category><![CDATA[Domain Driven Design]]></category>

		<guid isPermaLink="false">http://www.gridshore.nl/2010/08/08/axon-framework-0-6-released/</guid>
		<description><![CDATA[<p>Today, I released version 0.6 of the Axon Framework. 0.6 has many new features and is another step towards full production readiness. There is still some work to do, but first, let’s take a look at what has changed…</p> <p></p> <p>Test fixtures are now part of the axon-test module. These fixtures allow you to [...]]]></description>
			<content:encoded><![CDATA[<p>Today, I released version 0.6 of the Axon Framework. 0.6 has many new features and is another step towards full production readiness. There is still some work to do, but first, let’s take a look at what has changed…</p>
<p><span id="more-1070"></span></p>
<p>Test fixtures are now part of the axon-test module. These fixtures allow you to test your command handling logic based on events and commands. You define these tests in a given-when-then style: given these past events, when I execute this command, I expect these events to occur.</p>
<p>The <tt>CommandBus</tt> interface now allows for asynchronous command dispatching. Instead of using a return value, a Callback can be given to the command bus if you wish to be notified of the result of command execution.</p>
<p>The repositories make use of a <tt>UnitOfWork</tt> instance, which keeps track of changed aggregates and generated events. Instead of saving each aggregate separately, the <tt>UnitOfWork</tt> can be committed, causing changed aggregates to be stored, and events to be dispatched. With the new <tt>SimpleUnitOfWorkInterceptor</tt> or the <tt>SpringTransactionalInterceptor</tt>, it is no longer necessary to call <tt>repository.save()</tt>. In fact, you are discouraged from doing so.</p>
<p>Repositories are now capable of detecting conflicting modifications. When loading an aggregate, you may pass in the expected version of the aggregate. An exception is raised if that version does not match the actual version.</p>
<p>Event sourcing repositories allow for a more advanced way of detecting conflicts. Sometimes, not all concurrent modification are in conflict with each other. One user may very well change the shipping address of an order, while another user is adding items. Other modifications, however, are clearly conflicting, such as one user marking an order as shipped, and another one adding a product. For this purpose, you can register a <tt>ConflictResolver</tt> with the repository. This conflict resolver can, based on unseen and newly applied events, decide whether the changes made by the second user are accepted.</p>
<p>Axon now provides a mechanism to trigger snapshot creation based on the number of events needed to load to reconstitute an aggregate. When the number of events exceeds a given threshold, a snapshot is created and stored in the Event Store.</p>
<p>The <tt>SimpleCommandBus</tt> and <tt>SimpleEventBus</tt> now expose statistics over JMX. Although currently quite limited, the statistics will be improved in the coming versions.</p>
<p>All of these features help making applications with CQRS-based architectures even easier. But we’re not there yet. The coming months, we will try to make it even easier with features like Event versioning, support for aggregates with multiple entities, and whatever comes to mind in Axon’s growing community.</p>
<p>For more information about the Axon Framework, see <a href="http://www.axonframework.org">www.axonframework.org</a>.</p>
<div class='dd_post_share'><div class='dd_buttons'><div class='dd_button'><iframe src='http://widgets.dzone.com/links/widgets/zoneit.html?url=http%3A%2F%2Fwww.gridshore.nl%2F2010%2F08%2F08%2Faxon-framework-0-6-released%2F&amp;title=Axon%20Framework%200.6%20released&amp;t=2' height='25' width='155' frameborder='0' scrolling='no'></iframe></div></div><div style='clear:both'></div></div><!-- Social Buttons Generated by Digg Digg plugin v4.5.3.4, 
    Author : Yong Mook Kim
    Website : http://www.diggdigg2u.com -->]]></content:encoded>
			<wfw:commentRss>http://www.gridshore.nl/2010/08/08/axon-framework-0-6-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Axon Framework &#8211; the CQRS framework for Java &#8211; version 0.4 released</title>
		<link>http://www.gridshore.nl/2010/02/21/axon-framework-the-cqrs-framework-for-java-version-0-4-released/</link>
		<comments>http://www.gridshore.nl/2010/02/21/axon-framework-the-cqrs-framework-for-java-version-0-4-released/#comments</comments>
		<pubDate>Sun, 21 Feb 2010 15:57:56 +0000</pubDate>
		<dc:creator>Allard</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[DDD]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Axon Framework]]></category>

		<guid isPermaLink="false">http://www.gridshore.nl/2010/02/21/axon-framework-the-cqrs-framework-for-java-version-0-4-released/</guid>
		<description><![CDATA[<p>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 [...]]]></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://www.gridshore.nl/wp-content/uploads/logo1.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-1008"></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>
<div class='dd_post_share'><div class='dd_buttons'><div class='dd_button'><iframe src='http://widgets.dzone.com/links/widgets/zoneit.html?url=http%3A%2F%2Fwww.gridshore.nl%2F2010%2F02%2F21%2Faxon-framework-the-cqrs-framework-for-java-version-0-4-released%2F&amp;title=Axon%20Framework%20%26ndash%3B%20the%20CQRS%20framework%20for%20Java%20%26ndash%3B%20version%200.4%20released&amp;t=2' height='25' width='155' frameborder='0' scrolling='no'></iframe></div></div><div style='clear:both'></div></div><!-- Social Buttons Generated by Digg Digg plugin v4.5.3.4, 
    Author : Yong Mook Kim
    Website : http://www.diggdigg2u.com -->]]></content:encoded>
			<wfw:commentRss>http://www.gridshore.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>CQRS made easy with cqrs4j</title>
		<link>http://www.gridshore.nl/2009/12/21/cqrs-made-easy-with-cqrs4j/</link>
		<comments>http://www.gridshore.nl/2009/12/21/cqrs-made-easy-with-cqrs4j/#comments</comments>
		<pubDate>Mon, 21 Dec 2009 08:37:00 +0000</pubDate>
		<dc:creator>Allard</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[DDD]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[cqrs]]></category>
		<category><![CDATA[Domain Driven Design]]></category>

		<guid isPermaLink="false">http://www.gridshore.nl/?p=954</guid>
		<description><![CDATA[<p>&#160;</p> <p>Command Query Responsibility Segregation (CQRS) is an architectural style that makes a clear distinction between commands, which tell an application to do something, and queries, which are requests for information from an application. This distinction comes from the fact that the requirements (and thus also the model) for the execution and validation of [...]]]></description>
			<content:encoded><![CDATA[<p>&#160;<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="cqrs4j_logo" border="0" alt="cqrs4j_logo" align="left" src="http://www.gridshore.nl/wp-content/uploads/logo_large.png" width="100" height="100" /></p>
<p>Command Query Responsibility Segregation (CQRS) is an architectural style that makes a clear distinction between commands, which tell an application to do something, and queries, which are requests for information from an application. This distinction comes from the fact that the requirements (and thus also the model) for the execution and validation of commands are significantly different than those for queries. Events play an important role in the synchronization of application state resulting from executed command.</p>
<p>Applying a CQRS style architecture involves the development of quite a lot of “plumbing” code: event dispatching, asynchronous event processing, transactions, etc. <em>cqrs4j</em>, an Apache 2 licensed open source framework, takes care of all the plumbing for you. Read on to find out how…</p>
<p> <span id="more-954"></span><br />
<h2>A brief introduction to CQRS</h2>
<p>As I stated above, CQRS makes a distinction between the model that validates and executes commands and the model that is used for providing state information. This is quite significantly different than how most (web)app applications are build nowadays. In fact, the model used for commands (the box named “Domain” in the image below), does not expose any state, at all. You might wonder, but how do I know what to show in the front end? That comes directly from your data sources using a thin data layer. I’ll explain how the data gets there in a minute.<a href="http://www.gridshore.nl/wp-content/uploads/cqrs_architecture.jpg"><img style="border-bottom: 0px; border-left: 0px; display: block; float: none; margin-left: auto; border-top: 0px; margin-right: auto; border-right: 0px" title="cqrs_architecture" border="0" alt="cqrs_architecture" src="http://www.gridshore.nl/wp-content/uploads/cqrs_architecture_thumb1.jpg" 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>
<p>The asynchronous and event driven nature of CQRS makes it extremely valuable for complex applications that have different views on the information in the application. Integration with third party systems that need to be notified of certain changes in your application –and vice versa–&#160; is a lot easier if you use an event driven approach. And since event handling is done asynchronously, the application is more responsive and easier to scale. </p>
<p>But as you notice, there is quite a lot of processing and pushing around of events. When you have a customer breathing up your neck, you don’t want to be developing infrastructure code. You would want to be focusing on the business logic, which is quite complex by itself.</p>
<h2>cqrs4j</h2>
<p>cqrs4j is a Spring-oriented framework that provides the most important building blocks of a CQRS architecture. Creating an aggregate becomes really simple. You don’t have to worry about managing the storage and dispatching of (uncommitted) events. Event sourcing becomes as easy as wiring two beans in your application context.</p>
<p><strong>Annotation support</strong></p>
<p>cqrs4j comes with out-of-the-box annotation support. This makes is really easy to wire event handler methods. cqrs4j can automatically subscribe all your event handlers to the event bus and delegate all relevant events to the appropriate event handlers. Enabling annotation support is as easy as wiring a single bean in your application context.</p>
<p><strong>Spring Integration support</strong></p>
<p>Spring Integration is a framework that allows easy developments of a Messaging systems using the pipes-and-filters architecture. This fits nicely with most of the event dispatching process of CQRS. cqrs4j has support for Spring Integration, which allows you to publish all events as messages on a Spring Integration channel. Sending messages through JMS queues, via email, or through file system storage will only take a few lines of (XML) configuration.</p>
<p><strong>Transaction support</strong></p>
<p>If you update your database tables through incoming events, dealing with them one-by-one in a transaction can become time consuming and take up too much resources of your database. With cqrs4j, you can configure transactions just by setting the @Transactional annotation on your event handlers. You can also configure how many events should be handled in a single transaction.</p>
<h2>cqrs4j project page</h2>
<p>cqrs4j is an open source project, licensed under the Apache 2 license. Visit the project home page for the latest downloads, documentation and source code at <a href="http://code.google.com/p/cqrs4j" target="_blank">code.google.com/p/cqrs4j</a>.</p>
<p><strong>We welcome your feedback</strong></p>
<p>If you have any requests, remarks or other feedback, please let us know. You can report bugs and improvement requests on the <a href="http://code.google.com/p/cqrs4j/issues/" target="_blank">issues page</a>. You can also leave a message via the <a href="http://www.gridshore.nl/contact/" target="_blank">contact page</a> or by leaving a comment.</p>
<h2>Further reading</h2>
<p>I have some more CQRS related blog articles coming up, but there are already quite a few around. Here is a few that helped me get started:</p>
<ul>
<li><a href="http://www.infoq.com/presentations/greg-young-unshackle-qcon08" target="_blank">Greg Young @ QCon: Unshackle your domain</a> </li>
<li><a href="http://elegantcode.com/2009/11/11/cqrs-la-greg-young/" target="_blank">CQRS a la Greg Young</a> </li>
<li><a href="http://elegantcode.com/2009/11/20/cqrs-the-domain-events/" target="_blank">CQRS – The Domain Events</a> </li>
<li><a href="http://elegantcode.com/2009/12/08/cqrs-domain-state/" target="_blank">CQRS – Domain State</a> </li>
<li><a href="http://jonathan-oliver.blogspot.com/2009/10/dddd-why-i-love-cqrs.html" target="_blank">DDDD – Why I love CQRS</a> </li>
</ul>
<div class='dd_post_share'><div class='dd_buttons'><div class='dd_button'><iframe src='http://widgets.dzone.com/links/widgets/zoneit.html?url=http%3A%2F%2Fwww.gridshore.nl%2F2009%2F12%2F21%2Fcqrs-made-easy-with-cqrs4j%2F&amp;title=CQRS%20made%20easy%20with%20cqrs4j&amp;t=2' height='25' width='155' frameborder='0' scrolling='no'></iframe></div></div><div style='clear:both'></div></div><!-- Social Buttons Generated by Digg Digg plugin v4.5.3.4, 
    Author : Yong Mook Kim
    Website : http://www.diggdigg2u.com -->]]></content:encoded>
			<wfw:commentRss>http://www.gridshore.nl/2009/12/21/cqrs-made-easy-with-cqrs4j/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Second meetup DDDNL user group</title>
		<link>http://www.gridshore.nl/2009/10/01/second-meetup-dddnl-user-group/</link>
		<comments>http://www.gridshore.nl/2009/10/01/second-meetup-dddnl-user-group/#comments</comments>
		<pubDate>Thu, 01 Oct 2009 16:17:42 +0000</pubDate>
		<dc:creator>jettro</dc:creator>
				<category><![CDATA[DDD]]></category>

		<guid isPermaLink="false">http://www.gridshore.nl/?p=910</guid>
		<description><![CDATA[<p>Is has been more than a month a go that we had our first meeting, it is shorter than a month before we have the second event. The next event will take place on the 27th of october. The program for the event will be:</p> <p>17:30 &#8211; 18:30 pizza at JTeam office 18:30 &#8211; [...]]]></description>
			<content:encoded><![CDATA[<p>Is has been more than a month a go that we had our first meeting, it is shorter than a month before we have the second event. The next event will take place on the 27th of october. The program for the event will be:</p>
<p>17:30 &#8211; 18:30 pizza at JTeam office<br />
18:30 &#8211; 19:30 up to speed in DDD theory (by Rick van der Arend)<br />
19:30 &#8211; 19:45 coffee<br />
19:45 &#8211; 20:45 A practical perspective on DDD (by Wil Water)</p>
<p>You can register for the event by sending an email to info@dddnl.org.</p>
<p>regards Jettro</p>
<div class='dd_post_share'><div class='dd_buttons'><div class='dd_button'><iframe src='http://widgets.dzone.com/links/widgets/zoneit.html?url=http%3A%2F%2Fwww.gridshore.nl%2F2009%2F10%2F01%2Fsecond-meetup-dddnl-user-group%2F&amp;title=Second%20meetup%20DDDNL%20user%20group&amp;t=2' height='25' width='155' frameborder='0' scrolling='no'></iframe></div></div><div style='clear:both'></div></div><!-- Social Buttons Generated by Digg Digg plugin v4.5.3.4, 
    Author : Yong Mook Kim
    Website : http://www.diggdigg2u.com -->]]></content:encoded>
			<wfw:commentRss>http://www.gridshore.nl/2009/10/01/second-meetup-dddnl-user-group/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Introduction to DDD for the implementation oriented</title>
		<link>http://www.gridshore.nl/2009/08/24/introduction-to-ddd-for-the-implementation-oriented/</link>
		<comments>http://www.gridshore.nl/2009/08/24/introduction-to-ddd-for-the-implementation-oriented/#comments</comments>
		<pubDate>Mon, 24 Aug 2009 07:00:53 +0000</pubDate>
		<dc:creator>jettro</dc:creator>
				<category><![CDATA[DDD]]></category>

		<guid isPermaLink="false">http://www.gridshore.nl/?p=849</guid>
		<description><![CDATA[<p>Regular readers of gridshore know that Allard and I have attended a training on DDD (Domain Driven Design) and that we have started a user group for DDD in the Netherlands. Allard is using DDD for a project @ JTeam and he is starting to use it for a second project at JTeam as [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.gridshore.nl/wp-content/uploads/dddnl_logo.png" alt="dddnl_logo.png" border="0" width="152" height="95" align="left"/>Regular readers of gridshore know that Allard and I have attended a training on DDD (Domain Driven Design) and that we have started a user group for <a href="http://www.dddnl.org">DDD in the Netherlands</a>. Allard is using DDD for a project @ JTeam and he is starting to use it for a second project at JTeam as well. I am starting to use it on a few new initiatives and I am refactoring my old backoffice application to make it ready for a new version based on the DDD principles.</p>
<p>A lot of activity in the DDD area, and a lot of discussions with colleagues and other interested people about DDD. The biggest question is of course <strong>WHY?</strong>. There is not a very simple answer to this question. Ok, maybe one: <strong>Why not?</strong>. But that is to easy and not very convincing. A lot of arguments against DDD are coming from people talking about implementation problems. This blog post is focussing on those people. Not that others should not read it, but I am writing this post with those people in my mind.</p>
<p><span id="more-849"></span>
<p>When we were explaining DDD to developers we often heard: <em>Nothing different than what I am doing now, only other methods names</em>. We than tried to convince them from a technical perspective only. Of course this is very hard. Especially because your trying to compare apples with pears. Design is not implementation. People having a hard time giving DDD a place are often not doing design at all. They call thinking about technical problems design. This not the same design as the third D in DDD.</p>
<p>So, as an implementer, what should you know about DDD. Well first thing you should learn is that you need a domain expert to talk to. The second thing you must learn is to create a ubiquitous language with the complete team. The third thing to learn is how to combine the knowledge from a domain expert and some technical requirements and describe this using the mentioned ubiquitous language.</p>
<p>Domain Driven Design is about helping you achieve this. DDD presents some basic principles that help you to create better applications. Applications that you can explain to all members of the team and to the domain expert using the ubiquitous language.</p>
<p>This post introduces some basic things that I picked up from the training by Eric Evans. I do want to stress that reading about DDD is not a replacement for the actual training. The training in  itself is no replacement for doing actual projects using DDD.</p>
<h2>I am already doing domain driven design</h2>
<p><img src="http://www.gridshore.nl/wp-content/uploads/domaindiagram.png" alt="domaindiagram.png" border="0" width="216" height="262" align="right" /><br />
<em>We are doing domain driven design for all our projects. Look this is our domain model for a project.</em> Hmm, nice diagram. Well that is not completely what DDD is about. What does this diagram mean? Ahh, it is a graphical representation of the relationships between some of the most important entities and value objects of your model. But how did you get to this diagram? Did you talk to your domain expert? Does he understand it? Does it somehow reflect what he is thinking about when he is talking about his domain? Are all these terms known in the ubiquitous language? Are all project members talking about them in a consistent way?</p>
<p>DDD is not about creating a nice diagram. If diagrams help to understand the domain, it is wise to create them. Very often the creation of the diagram is helping to understand the domain. Usually developers and domain experts understand these kind of diagrams. But please do not call this diagram <strong>the model</strong>. The idea about DDD is to create a model using a ubiquitous language. To get better insights into the model, diagrams can surely help.</p>
<h2>Of course I talk to the client</h2>
<p>A very big part about DDD is talking to the domain expert. You must learn how to get information from a domain expert. Learn about the domain. When talking to people representing the client, make sure you are talking to a domain expert.</p>
<p>A few tips when interacting with the domain expert:</p>
<ul>
<li>When talking to the domain expert, make it a conversation. You should have mutual interest in having these talks.</li>
<li>Share your own ideas around the model.</li>
<li>Use multiple different ideas to get the discussion going.</li>
<li>Bad ideas are good, they teach you a lot about what it is not.</li>
<li>Use bad examples to see if you understand the domain expert and if he is still with you.</li>
<li>Use scenarios to talk about the domain and the model. Also use realistic values, that way the domain expert knows better what you are talking about and you get a better feeling with your domain.</li>
<li>Don&#8217;t think you need to talk to the domain expert once, make sure he is available to you the complete project.</li>
</ul>
<h2>Here is my Model</h2>
<p>Central to domain driven design is the model. We all have an idea what a model is. To me the context for the model is very important. Do not make a model as realistic as possible. The model is a simplification of the domain. You leave out everything that is not needed for your specific need.</p>
<p>The model must be intuitive to users and simple to learn. In order to find the right model you should try to apply different scenarios to the model. If the domain expert does not understand the model, cannot talk about scenarios with respect to the model, the model is wrong. If the model is wrong, your code is wrong. If the code is wrong, I guess you understand what that means.</p>
<h2>Context Map</h2>
<p>I real eye opener to me during the training from Eric Evans was the context map. If you have read the book from eric, you can find it in his book. There is a <a href="http://www.domaindrivendesign.org/resources/ddd_terms">small summary of the terms discussed online</a>.</p>
<p>If your complete system becomes bigger and you need integrations with other systems, it is a very good time for a Context Map. The complete solution might exist from different contexts. Each context is created by different teams and often by different companies. With a context map, you plot these context and focus on their relationships. The type of relationship between two different contexts has it&#8217;s influence on the domain model.</p>
<p>An example: <br/>A small company A uses a component from company B for plotting points of interest on a map. Now company A needs a feature to add extra characteristics to points of interest on the Map. Company B has no interest for these additional properties and do not change the model. This is a good example of a customer-supplier relationship. Does company A use the model of company B for it&#8217;s points of interest map? Or does company A create an adapter for all communication to company B and do data transformation. That way there is not dependency on the model of company B. Eric calls the first scenario a <em>Conformist</em> and the second an <em>Anti corruption layer</em>. The anti corruption layer is expensive at the start, but gives a lot of flexibility. </p>
<p>Eric discussed other relationships as well, things like: Shared Kernel, Separate ways, Open host and published language. These concepts are not new, but now they have a name. Plotting them on a context map and making them explicit in your ubiquitous language helps you when making choices in your model.</p>
<h2>DDD is hard to implement</h2>
<p>Depending on who you are talking to, implementing DDD has different challenges. One thing often mentioned is that the domain objects need to take care of their own persistence. All hard things to inject data access components into the domain object are considered by these people. I do not believe in that direction. I&#8217;ll take away transaction, security and persistence from the domain entities. The application services take care of the transaction boundaries and repository objects take care of the persistence. The <a href="http://www.gridshore.nl/2009/07/01/designing-the-repository-interface/">post from Allard about the repository interface</a> gives you an idea. More posts on this topic are coming.</p>
<p>A few things to think about while implementing</p>
<ul>
<li>Make sure the domain expert available to the team.</li>
<li>Make sure the designers are writing the code as well.</li>
<li>Let the model drive the code.</li>
<li>Use the domain expert while coding. Spotting code duplication might be a misunderstanding in the model. Talk to the domain expert. This is also the case when you want to do a refactoring in the model.</li>
<li>Create intention revealing interfaces and side effect free functions.</li>
<li>Make the left side of statements read the same as the right side:<br/>Itinerary truncatedItinerary = itinerary.truncatedAt(routingPoint);</li>
<li>Use Equals and HashCode methods as they were meant to be used.(see <a href="http://www.gridshore.nl/2009/07/29/domain-driven-design-and-the-equals-method/">blog post Allard</a>)</li>
<li>Learn from other solutions, for instance infrastructure mechanisms for repositories.</li>
<li>Do not try to copy domains. Most certainly they have been used in a different context. Of course you can learn from other models, use them for inspiration.</li>
</ul>
<p>DDD is Domain Driven Design, it is not called DDI (Domain Driven Implementation). Do not come to me and tell me that it is impossible to implement DDD. If you are designing an application that cannot be implemented, that is a whole different problem.</p>
<h2>Final remarks</h2>
<ul>
<li>Do not design for technology, design for the domain.</li>
<li>Use short feedback cycles with the domain expert, test first and verify solutions with the domain expert.</li>
<li>Do not loose all technical perspective in design, but let the domain guide you in technical choices like: remoting, caching, transactions boundaries.</li>
<li>The biggest impact in domain driven design is that your code can be understood by domain experts. That way problems in your code can be solved like in the domain. So you can actually copy the solution that the domain expert has been using for years into your design.</li>
<li>The developer cannot make domain driven design a succes on his own. He needs the complete team.</li>
<li>Make sure the design and implementation are tightly coupled.</li>
</ul>
<p>That&#8217;s it. I hope I inspired some of you to have a better look at DDD. If you are living in the Netherlands you can attend a tech evening of JTeam, we will give an introduction into DDD. You can send an email to techmeeting@jteam.nl if you want to attend (3 september 2009, we start at 16:00). Another thing I would like to bring to the attention of the dutch readers is the DDDnl usergroup. We are planning our first session the 8th of september 2009. You can register yourself for the usergroup and for the session on the homepage of the usergroup. <a href="http://www.dddnl.org">http://www.dddnl.org</a></p>
<div class='dd_post_share'><div class='dd_buttons'><div class='dd_button'><iframe src='http://widgets.dzone.com/links/widgets/zoneit.html?url=http%3A%2F%2Fwww.gridshore.nl%2F2009%2F08%2F24%2Fintroduction-to-ddd-for-the-implementation-oriented%2F&amp;title=Introduction%20to%20DDD%20for%20the%20implementation%20oriented&amp;t=2' height='25' width='155' frameborder='0' scrolling='no'></iframe></div></div><div style='clear:both'></div></div><!-- Social Buttons Generated by Digg Digg plugin v4.5.3.4, 
    Author : Yong Mook Kim
    Website : http://www.diggdigg2u.com -->]]></content:encoded>
			<wfw:commentRss>http://www.gridshore.nl/2009/08/24/introduction-to-ddd-for-the-implementation-oriented/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Domain Driven Design and the equals method</title>
		<link>http://www.gridshore.nl/2009/07/29/domain-driven-design-and-the-equals-method/</link>
		<comments>http://www.gridshore.nl/2009/07/29/domain-driven-design-and-the-equals-method/#comments</comments>
		<pubDate>Wed, 29 Jul 2009 08:46:52 +0000</pubDate>
		<dc:creator>Allard</dc:creator>
				<category><![CDATA[DDD]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[best practices]]></category>
		<category><![CDATA[Domain Driven Design]]></category>
		<category><![CDATA[equals]]></category>

		<guid isPermaLink="false">http://www.gridshore.nl/2009/07/29/domain-driven-design-and-the-equals-method/</guid>
		<description><![CDATA[<p>Implementing an equals method in Java can be quite complicated. Fortunately there are numerous document around the web with useful tips, hints and frameworks to assist you in this process. However, an implementation of the equals method that is technically correct doesn’t have to make any sense functionally. In Domain Driven Design, your domain [...]]]></description>
			<content:encoded><![CDATA[<p>Implementing an equals method in Java can be quite complicated. Fortunately there are numerous document around the web with useful tips, hints and frameworks to assist you in this process. However, an implementation of the equals method that is technically correct doesn’t have to make any sense functionally. In <a href="http://domaindrivendesign.org/" target="_blank">Domain Driven Design</a>, your domain model implementation is the beating heart of your application. Everything has to make perfect (functional) sense in there. Having good equals methods is of vital importance there.</p>
<p>In this article, I will elaborate on some common pitfalls you can encounter when implementing the equals method, as well as some sensible guidelines.</p>
<p> <span id="more-838"></span>
<p>A lot of IDE’s nowadays allow you to generate technically perfect and compliant implementations of the equals method for any object. You simply choose a number of properties you wish to include in the comparison, indicate some of them as being non-null values and voila. Write a small unit test for the thing, commit the whole shebang and you’re done. Well, not quite. You’ve probably got an implementation even worse than the one provided by Object.</p>
<p>I’ve seen developers generate equals methods in mere seconds. Although managers tend to love this sort of “productivity”, as an architect doing code reviews, I measure productivity differently. I doubt if any developer can properly evaluate the functional value of such an implementation in just seconds.</p>
<p>First, we need to define what equals really means. To me, when to objects are equals, it means they are to such a degree identical to each other, that they can be replaced without side effects. In other words, if two objects are equal, it doesn’t matter which one you pick. In math, equality is very well defined. In software, it is a little harder to achieve that level of definitions. But that doesn’t mean we shouldn’t try.</p>
<p>As the title of this article suggests, I want to look at the equals method in the context of Domain Driven Design (DDD). In DDD, it’s all about making concepts explicit. In our case, it means answering the question: “What does it mean, for two [fill in the blank] to be equal?” Of course, there isn’t really a single generic answer for all objects. However, objects can be classified into a few major groups in DDD: Entities, Value Objects and (Domain)Services. The last of the three is not really of much interest in this context, so let’s focus on the other two.</p>
<p><strong>Value objects</strong></p>
<p>Value objects are immutable objects of which only the properties are of importance. They carry no concept of identity. A perfect example of a value object in daily life is money. Personally, I don’t care which 10 euro bill I carry, as long as it is a valid 10 euro’s. You can swap it with one owned by a friend and you won’t feel better or worse about it. The two bills are equal.</p>
<p>Because of the immutability in value objects, testing them for equality is rather easy. Generally, you can just generate an equals method using all of the (exposed) properties of the object. In our example, as long as the currency and the amount is the same, we don’t really care which instance of the bill we carry with us.</p>
<p>Therefore: the default choice for the equals method on value objects should be to include all (exposed) properties of that value object in the comparison.</p>
<p><strong>Entities</strong></p>
<p>En entity is “an object fundamentally defined not by its attributes, but by a thread of continuity and identity.” In daily life, having the same name as somebody else doesn’t make you the same. This form of mistaken identity can lead to huge problems in an application.</p>
<p>But back to our equals implementation. What does it mean for two entities to be equal? Well, it should mean that they can replace each other without side effects. If they can’t replace each other, they can’t really be equal. This means that, for to entities to be equal, at least their identity should be equal.</p>
<p>But entities have mutable state. To what degree do you want to use that state in the comparison? That really depends on the context of the comparison. If you want to know if the state has been modified between two copies of the instance, you will need an equals method that checks on all mutable properties as well as the identity. If you are only interested in knowing whether you are talking about an object representation of the actual same thing, identity comparison is the only thing you need.</p>
<p>If there is one thing an equals method cannot do, it is to look at the context and intentions of the caller. Since it extremely important to use “intention revealing interfaces”, an equals method on an entity is probably not the right way to go. In a discussion with Eric Evans, he explained that he prefers not to implement equals on entities at all, and instead provide other comparison methods, such as “hasSameIdentityAs”. This method clearly states what it means to be the same. Depending on the context and intention of your comparison, you call another method.</p>
<p>Let’s go back to the statement about equality: when two objects are equal, it means that you can replace one with the other without side effects.</p>
<p>Replacing one entity instance with another is dangerous in most circumstances. If they have the same identifier, they might have different state. The different instances are likely to be used by different threads with different intentions. When using persistence frameworks like JPA, your entity is likely to be attached to a persistence context, meaning that replacing them without side effect is out of the question.</p>
<p>This probably means that this statement is a little too rigid for entities. Mechanisms like the Set rely on the equals method to decide whether you are allowed to add an item or not.</p>
<p>Personally, I like to define two entities as equal when you are talking about the representation of the same actual thing. Hence, when the type and identity of the two are the same. This means my choice of equals method will only take the actual class and identity into consideration.</p>
<p>This gives us a nice problem when identity is provided by the persistence framework at the time an object is persisted. How do you measure equality when one or both instances do not (yet) have an identity? Although you cannot (or should not) try to predict the identity of those instances, there is one thing you can say about it. If two different instances have no identity, there is no way a persistence framework will assign them the same identity. This means that you can revert to the default implementation of equals in that case (practically doing a == comparison). The same goes for comparison of an entity with identity and one without: they will never, ever have the same identity in the future.</p>
<p><strong>Conclusion</strong></p>
<p>Before implementing the equals method, think clearly about the type of object that you are comparing. If it is an immutable value object, you should include all (exposed) properties of the value object. If it is an entity, be very cautious and first define what equality really means. Consider using methods with intention revealing interfaces, such as “hasSameIdentityAs” and “hasSameStateAs”.</p>
<div class='dd_post_share'><div class='dd_buttons'><div class='dd_button'><iframe src='http://widgets.dzone.com/links/widgets/zoneit.html?url=http%3A%2F%2Fwww.gridshore.nl%2F2009%2F07%2F29%2Fdomain-driven-design-and-the-equals-method%2F&amp;title=Domain%20Driven%20Design%20and%20the%20equals%20method&amp;t=2' height='25' width='155' frameborder='0' scrolling='no'></iframe></div></div><div style='clear:both'></div></div><!-- Social Buttons Generated by Digg Digg plugin v4.5.3.4, 
    Author : Yong Mook Kim
    Website : http://www.diggdigg2u.com -->]]></content:encoded>
			<wfw:commentRss>http://www.gridshore.nl/2009/07/29/domain-driven-design-and-the-equals-method/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>User group for DDD enthusiasts in the Netherlands started</title>
		<link>http://www.gridshore.nl/2009/07/24/user-group-for-ddd-enthousiast-in-the-netherlands-started/</link>
		<comments>http://www.gridshore.nl/2009/07/24/user-group-for-ddd-enthousiast-in-the-netherlands-started/#comments</comments>
		<pubDate>Fri, 24 Jul 2009 14:00:43 +0000</pubDate>
		<dc:creator>jettro</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[DDD]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.gridshore.nl/?p=834</guid>
		<description><![CDATA[<p>Today we release the website of a new User group for all Domain Driven Design enthusiasts. This user group is meant to facilitate all experienced DDD people to unity and share ideas/experiences. We also would like to help starters getting up to speed learning more about DDD</p> <p>What are we planning to do? We [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.gridshore.nl/wp-content/uploads/dddnl_logo.png" alt="dddnl_logo.png" border="0" width="152" height="95" align="left" />Today we release the website of a new User group for all Domain Driven Design enthusiasts. This user group is meant to facilitate all experienced DDD people to unity and share ideas/experiences. We also would like to help starters getting up to speed learning more about DDD</p>
<p>What are we planning to do? We are planning (bi-)monthly events. During these events people can share ideas in a presentation, discussions. We might have (international) guests coming in to talk about Domain Driven Design. Everything is focused around knowledge sharing. I suggest to <a href="http://www.dddnl.org">check the website</a> for more details.</p>
<p>The user group is connected to the <a href="http://www.domaindrivendesign.org">domain driven design</a> website hosted by Eric Evens and others.</p>
<p>If you are up to it, feel free to register for the kick-off event that is taking place the 8th of September. You can use the <a href="http://www.dddnl.org/node/9">form on the website</a> to register.</p>
<p>I hope all people get as enthusiastic as we are.</p>
<p>regards Jettro and Allard</p>
<div class='dd_post_share'><div class='dd_buttons'><div class='dd_button'><iframe src='http://widgets.dzone.com/links/widgets/zoneit.html?url=http%3A%2F%2Fwww.gridshore.nl%2F2009%2F07%2F24%2Fuser-group-for-ddd-enthousiast-in-the-netherlands-started%2F&amp;title=User%20group%20for%20DDD%20enthusiasts%20in%20the%20Netherlands%20started&amp;t=2' height='25' width='155' frameborder='0' scrolling='no'></iframe></div></div><div style='clear:both'></div></div><!-- Social Buttons Generated by Digg Digg plugin v4.5.3.4, 
    Author : Yong Mook Kim
    Website : http://www.diggdigg2u.com -->]]></content:encoded>
			<wfw:commentRss>http://www.gridshore.nl/2009/07/24/user-group-for-ddd-enthousiast-in-the-netherlands-started/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Designing the Repository interface</title>
		<link>http://www.gridshore.nl/2009/07/01/designing-the-repository-interface/</link>
		<comments>http://www.gridshore.nl/2009/07/01/designing-the-repository-interface/#comments</comments>
		<pubDate>Wed, 01 Jul 2009 19:58:49 +0000</pubDate>
		<dc:creator>Allard</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[DDD]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.gridshore.nl/2009/07/01/designing-the-repository-interface/</guid>
		<description><![CDATA[<p>In one of my most recent projects, I decided to design and build the application according to the principles of Domain Driven Design. One of the guidelines promoted by Domain Driven Design is the way the interface of the Repository is designed. This changed the way I look at both the design and the [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.gridshore.nl/wp-content/uploads/storage.jpg"><img style="border-right-width: 0px; margin: 0px 10px 0px 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="storage" border="0" alt="storage" align="left" src="http://www.gridshore.nl/wp-content/uploads/storage_thumb.jpg" width="104" height="96" /></a>In one of my most recent projects, I decided to design and build the application according to the principles of <a href="http://domaindrivendesign.org/" target="_blank">Domain Driven Design</a>. One of the guidelines promoted by Domain Driven Design is the way the interface of the Repository is designed. This changed the way I look at both the design and the location of the <a href="http://www.martinfowler.com/eaaCatalog/repository.html" target="_blank">Repository</a> interface. It’s all gain, no pain.</p>
<p>&#160;</p>
<p> <span id="more-823"></span>
<p>Most of the applications I encounter in my <a href="http://www.jteam.nl" target="_blank">work</a> as Software Architect apply more or less the same layering. The well-known layers in an application are the web layer, application layer, persistence layer and domain layer. This layering provides some boundaries for different types of logic to keep an application maintainable in the long term. Typically, layers are placed in different modules (each with their own jar file) inside a project. However, for smaller projects it would suffice to just place each layer in its own package structure.</p>
<p><a href="http://www.gridshore.nl/wp-content/uploads/typicalapplicationlayering.jpg"><img style="border-right-width: 0px; margin: 0px 10px 0px 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="typical-application-layering" border="0" alt="typical-application-layering" align="left" src="http://www.gridshore.nl/wp-content/uploads/typicalapplicationlayering_thumb.jpg" width="220" height="163" /></a> </p>
<p>Almost all applications I encounter have implemented a layering as shown in the image on the left. The arrows show the direction of the dependency of each module on the others.</p>
<p>As you can see, the Application Layer has a dependency on the Persistence layer. The need for that dependency comes from the fact that the persistence layer contains the Repository. Both the interface (since it is good practice to develop against interfaces) and its implementation. With my recent study of the Domain Driven Design principles, I gained the insight that it doesn’t really make a lot of sense to put the interface next (or near) to its implementation.</p>
<p>But why would you even bother to create an interface for the Repository at all? Well, there are a few good reasons (and probably some bad ones too) to do so. One of them is that it allows easy mocking and stubbing for tests. Another is that it allows you to replace or modify the implementation without the risk of breaking interaction (as long as the interface is maintained).</p>
<p>However, replacing the persistence layer with another one isn’t as easy as it seems when it contains the interface. To be able to do so, you must copy the interface into the new persistence layer implementation. And as any good developers knows, when you’re copying stuff, take your hands off the keyboard, and think for a second. You’re probably doing something wrong.</p>
<p>Quite recently, I had a small discussion with someone who said: “How often do you expect to change the implementation of your persistence layer?”. I didn’t really have an answer back then, but right now I am spending time on exactly that in one of my projects. And you’ll have to trust me on this: correctly designing the interface is well worth the trouble. Even if you only have to change the persistence implementation once every 100 projects. Furthermore, another project I recently started actually requires the ability to “plug in” different implementations of the persistence layer (no, not at runtime, it doesn’t have to be OSGi, unfortunately).</p>
<p><a href="http://www.gridshore.nl/wp-content/uploads/betterapplicationlayering.jpg"><img style="border-right-width: 0px; margin: 0px 0px 0px 10px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="better-application-layering" border="0" alt="better-application-layering" align="right" src="http://www.gridshore.nl/wp-content/uploads/betterapplicationlayering_thumb.jpg" width="220" height="163" /></a>Inspired by the <a href="http://www.domaindrivendesign.org/examples" target="_blank">DDD sample application</a>, I decided to place the interface in the Domain Layer. By doing this, there was no longer a need to have a (compile time) dependency from the Application layer to the Persistence layer. On paper that looks a bit cleaner.&#160; But we don’t design applications to look good on paper.</p>
<p>A good repository interface, as described by Martin Fowler and Eric Evans, gives it’s client the perception of an in-memory repository. In fact, it should hide any implementation choices you make about how and where data is really stored. And if you want to be able to replace persistence layers, that’s exactly what you need.</p>
<p>If you place the interface next to an implementation, you’re tempted to just use your IDE to extract an interface from your implementation. Chances are that your interface “leaks” information of your implementation choices. Instead, try to force yourself to design the interface first and develop an implementation that conforms to that interface later. This will help you achieve the “in-memory” perception.</p>
<p>A colleague of mine asked me why I chose to put the interface in the domain layer (see <a href="http://www.martinfowler.com/eaaCatalog/separatedInterface.html" target="_blank">Separated Interface Pattern</a>), and not the application layer, which is most likely to need the interface and call its implementation.I had three reasons. </p>
<p>First, the interface is described based on a small selection of domain entities. This gives the interface high coupling with these domain objects. High coupled classes are good candidates to share a package. In fact, you repository interface probably doesn’t require any import statements at all.</p>
<p>Secondly, it is probable that more than one service, perhaps located in different packages or modules, need to use the same repository. In that case, which package is most suitable to put the implementation in? Choosing even another package will result in lots of inter-package dependencies that aren’t really necessary. Unnecessary package dependencies decrease the ability to refactor your application .</p>
<p>And thirdly, the repositories provide access to your “aggregate roots”. If you have an aggregate root named, for example, “Order” and call your repository “OrderRepository”, your IDE will sort these classes in such a way, that you can easily find the most important entities in a blink of an eye.</p>
<p>Well, I hope this can help you in your projects as it could have helped me in the past. If you have any questions or concerns, don’t hesitate to leave a comment.</p>
<div class='dd_post_share'><div class='dd_buttons'><div class='dd_button'><iframe src='http://widgets.dzone.com/links/widgets/zoneit.html?url=http%3A%2F%2Fwww.gridshore.nl%2F2009%2F07%2F01%2Fdesigning-the-repository-interface%2F&amp;title=Designing%20the%20Repository%20interface&amp;t=2' height='25' width='155' frameborder='0' scrolling='no'></iframe></div></div><div style='clear:both'></div></div><!-- Social Buttons Generated by Digg Digg plugin v4.5.3.4, 
    Author : Yong Mook Kim
    Website : http://www.diggdigg2u.com -->]]></content:encoded>
			<wfw:commentRss>http://www.gridshore.nl/2009/07/01/designing-the-repository-interface/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>The power of immutability in a Rich Domain Model</title>
		<link>http://www.gridshore.nl/2009/04/06/the-power-of-immutability-in-a-rich-domain-model/</link>
		<comments>http://www.gridshore.nl/2009/04/06/the-power-of-immutability-in-a-rich-domain-model/#comments</comments>
		<pubDate>Mon, 06 Apr 2009 19:00:00 +0000</pubDate>
		<dc:creator>Allard</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[DDD]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[design patterns]]></category>
		<category><![CDATA[domain model]]></category>
		<category><![CDATA[software design]]></category>

		<guid isPermaLink="false">http://www.gridshore.nl/?p=696</guid>
		<description><![CDATA[<p>As many other developers, I’ve been used to the fat service layer and the anemic domain model of the transaction script pattern. In that programming model, immutability is pretty much as rare as a Dodo. However, I have been investigating the rich domain model pattern lately (as you can read in my previous post) [...]]]></description>
			<content:encoded><![CDATA[<p>As many other developers, I’ve been used to the fat service layer and the anemic domain model of the <a href="http://martinfowler.com/eaaCatalog/transactionScript.html" target="_blank">transaction script</a> pattern. In that programming model, immutability is pretty much as rare as a <a href="http://en.wikipedia.org/wiki/Dodo" target="_blank">Dodo</a>. However, I have been investigating the rich domain model pattern lately (as you can read in my <a href="http://www.gridshore.nl/2009/01/27/injecting-domain-objects-with-spring/">previous post</a>) and more importantly, a good migration path for “<a href="http://martinfowler.com/eaaCatalog/transactionScript.html" target="_blank">transaction script</a>” developers to get acquainted with the rich <a href="http://martinfowler.com/eaaCatalog/domainModel.html" target="_blank">Domain Model</a>, a design pattern that has been heavily underrated (and misunderstood) by many.</p>
<p>In this post, I will explain some of the advantages that immutable domain objects bring us, while showing that some of the seemingly problematic side effects aren’t really that problematic.</p>
</p>
<p> <span id="more-696"></span>
</p>
<p>A practical example is often the easiest way to explain these kind of things. Since the banking world has received enough discredit in these times, I will use another example than the infamous “withdrawal” example. Instead, we will use the almost-as-infamous product and order example.</p>
<p>Imagine an application where you can browse trough products and place an order for one or more of those products. Our simple domain will contain three entities: product, order and order line. A UML class diagram for this domain is shown below.</p>
<p><img title="power_of_immutability_class_diagram_1" style="border-top-width: 0px; display: block; border-left-width: 0px; float: none; border-bottom-width: 0px; margin-left: auto; margin-right: auto; border-right-width: 0px" height="216" alt="power_of_immutability_class_diagram_1" src="http://www.gridshore.nl/wp-content/uploads/power-of-immutability-class-diagram-12.jpg" width="323" border="0" /></p>
<h3>The anemic approach</h3>
<p>A commonly seen approach to implement this domain model is the following. The Order is implemented containing some delivery details and a list of order lines. The Order exposes getters and setters to modify each of those properties, including a getter that provides access to the list of order lines. The implementation of the OrderLine class is similar; it might contain a reference to a Product instance as well as a property to indicate the quantity ordered, resulting in the following code:</p>
<pre>
<pre class="brush: java; title: ; notranslate">
public class OrderLine {
    private Product product;
    private int quantity; 

    public Product getProduct() {
        return product;
    } 

    public void setProduct(final Product product) {
        this.product = product;
    } 

    public int getQuantity() {
        return quantity;
    } 

    public void setQuantity(final int quantity) {
        this.quantity = quantity;
    }
}
</pre>
</pre>
<p>This code has a few problems, some functional and some technical</p>
<ul>
<li>What happens if the price of the product changes? Invoices will probably show the new price (which is always higher, for some reason). </li>
<li>It’s no longer possible to delete a product, since you won’t be able to see what somebody ordered </li>
<li>You allow every other class in your application to modify the OrderLine at will. What if you have a discount for customers that order for a certain amount? Each time an order line was modified, your code would have to call a <code>calculateDiscount</code> in your order </li>
<li>If you want to calculate the total price of an order, you would have to iterate through all OrderLine and Product instances. </li>
</ul>
<p>Of course, each of those problems can be solved some way or another, but whatever you do to solve them, it only adds to the complexity already there.</p>
<h3>The immutable approach</h3>
<p>Making the OrderLine immutable will solve some of the problems outlined above. The state of immutable objects is exclusively set in the constructor, meaning that both the Product and quantity will have to be passed as constructor parameters.</p>
<p>To solve the problem of the Product changing state, we can copy some of the important fields into the OrderLine. Good candidates for copying are the product identifier, the product name and its price. In fact, we don’t need any reference to the original Product instance at all after the OrderLine has been constructed.</p>
<p>The implementation of the immutable OrderLine is then changed into the following:</p>
<pre>
<pre class="brush: java; title: ; notranslate">
public class OrderLine {

    private final String productIndentifier;
    private final String productName;
    private final Price itemPrice;
    private final Price totalPrice;
    private final int amount;

    public OrderLine(Product product, int amount) {
        this.productIndentifier = product.getIdentifier();
        this.productName = product.getName();
        this.itemPrice = product.getPrice();
        this.totalPrice = itemPrice.multiply(amount);
        this.amount = amount;
    }

    /* getters not shown for brevity */
}
</pre>
</pre>
<p>All problems solved? Well, no, not really. For starters, the last two problems enumerated above are still not solved. And then there is persistence. I use hibernate for nearly every project that requires persistence. Hibernate and immutable objects are not the best friends possible. Hibernate requires a non-private default constructor. Doesn’t seem like a problem, just add a no-argument constructor to you class. But then the <code>final</code> keyword ruins the game. You’ve got no other choice than to remove it. This removed the guaranteed visibility when your class is accessed by different threads at the same time. Solving that is a totally different ballgame and would carry me way off topic.</p>
<h3>Using an aggregate root</h3>
<p>We still have the problem that our discount is not updated when OrderLine instances are added or removed from an order. Making an order immutable in the same fashion would solve the problems. But let’s assume that a user is allowed to update and modify his orders as long they haven’t been processed by the system.</p>
<p>Exposing the list of OrderLine entries inside an order is not a good way to go, since your order is not in charge of its own lifecycle. If you take a close look at the UML diagram above, you will notice there is a composite relationship between the Order and OrderLine classes. This means that the Order class is responsible for the lifecycle of the OrderLine items that belong to it. In Domain Model terms, this means that Order is the <a href="http://domaindrivendesign.org/discussion/messageboardarchive/Aggregates.html" target="_blank">Aggregate Root</a> of these components.</p>
<p>The order would then be implemented as follows:</p>
<pre>
<pre class="brush: java; title: ; notranslate">
public class Order {

    private final List&lt;orderline&gt; orderLines = new ArrayList&lt;orderline&gt;();
    private final Customer customer;
    private Address shippingAddress;
    private Price totalAmount;

    public Order(Customer customer) {
        this.customer = customer;
    }

    public List&lt;orderline&gt; getOrderLines() {
        return Collections.unmodifiableList(orderLines);
    }

    public void addToOrder(Product product, int amount) {
        removeFromOrder(product);
        final OrderLine orderLine = new OrderLine(product, amount);
        orderLines.add(orderLine);
        totalAmount = totalAmount.add(orderLine.getTotalPrice());
        calculateDiscount();
    }

    public void removeFromOrder(Product product) {
        // implementation left to your imagination
    }

    /* rest of implementation left out for brevity */
}
</pre>
</pre>
<p>As you can see, a high level of encapsulation has been applied. It is now impossible to change any state of the Order or OrderLine without the Order knowing it. The list of OrderLine items that the Order exposes is made immutable using the utility method in the Collections class.</p>
<p>With this implementation, it the latter two of the problems enumerated above have been solved. Since the order is in charge of making the changes to its own state, it is rather easy to discover state changes that might impact applicable discounts or change the total amount of the order. Now, getting access to the amount of the order is as easy as returning the <code>totalAmount</code> property from the Order.</p>
<h3>Conclusion</h3>
<p>In this post, I’ve introduced a very powerful concept to manage the state of complex domain models: immutability. By preventing the application to change state directly, you gain more control over the the actions that need to be taken when the state changes. Especially in aggregates, immutability reduces the complexity of state management.</p>
<p>However, when using Hibernate, it is impossible to make an entity completely immutable using the final keywords. In that case it is sufficient to create a default constructor with package visibility and removing the final keywords.</p>
<div class='dd_post_share'><div class='dd_buttons'><div class='dd_button'><iframe src='http://widgets.dzone.com/links/widgets/zoneit.html?url=http%3A%2F%2Fwww.gridshore.nl%2F2009%2F04%2F06%2Fthe-power-of-immutability-in-a-rich-domain-model%2F&amp;title=The%20power%20of%20immutability%20in%20a%20Rich%20Domain%20Model&amp;t=2' height='25' width='155' frameborder='0' scrolling='no'></iframe></div></div><div style='clear:both'></div></div><!-- Social Buttons Generated by Digg Digg plugin v4.5.3.4, 
    Author : Yong Mook Kim
    Website : http://www.diggdigg2u.com -->]]></content:encoded>
			<wfw:commentRss>http://www.gridshore.nl/2009/04/06/the-power-of-immutability-in-a-rich-domain-model/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
	</channel>
</rss>

