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.