cameronfletcher.com

random thoughts and discussions on the things that interest me

CQRS Presentation

I recently gave a presentation on Command and Query Responsibility Segregation (CQRS) as a follow-on from my event sourcing talk. This is really an overview of my understanding of CQRS which has been heavily influenced by the DDD community and shaped by the experiences that I’ve gained in my job over the past 18 months.

In contrast to my last presentation the content of this one was mostly my own. A large part of the talk was demonstration of a working CQRS application which I stepped through in debug mode to illustrate the flow of data in the system. The source code for that application can be found here: http://hg.cameronfletcher.com/brownbag

The reaction to the talk was positive and, once more, it generated quite a bit of debate. As before, for those that attended (or are interested) my course the slides and notes for my presentation can be found here: cqrs.pptx

CQRS and when the Penny Dropped

I’ve been working on a project for a while now where the requirement is to provide a more scalable and better performing version of an existing system.

We chose to base the new system on Greg Young’s open-source SimpleCQRS project. Earlier this week I was refactoring one of the domain objects when I came across something like the following:

private string description;

public string Description
{
    get { return this.description; }
}

public void ChangeDesciption(string description)
{
    ApplyChange(new DescriptionChanged { Description = description });
}

private void Apply(DescriptionChanged @event)
{
    this.description = @event.Description;
}

I noted that the public Description property was unused, so I removed it.

Then the penny dropped.

I noticed that I could remove the private description property too because it was not used in any of the business logic. Then the previous sixteen lines of code became the following four:

public void ChangeDesciption(string description)
{
    ApplyChange(new DescriptionChanged { Description = description });
}

Less code. More sense. And a growing realisation that I had been confusing the responsibility of the GUI to display the description of the product with that of the domain object which was only concerned with business logic – something that the product description had nothing to do with.