Friday, March 27, 2009

The Query Command Separation principle, who was right?

Yesterday, at my Design Patterns & Testability session at the dotNED meeting, I tried to explain the purpose of the Query Command Separation principle. However, somebody from the company Quadrant (forgot to ask for his name) mentioned an entirely different explanation of the pattern. Since many design principles are not very well specified, I was expecting some discussion, but in this case, I was caught off guard a little bit.

He was explaining it as a pattern for distributing changes over multiple synchronized databases. For instance, when one database is used for reporting or querying and the other for maintaining state, command-like objects are used to apply the same change to both databases. I heard about this approach and it sounded like the Command pattern. However, he mentioned an article from Greg Young posted on Code Better, so it sounded serious enough for me to investigate.

Turns out we were both right. As a technical design pattern, the QCS principle does indeed what I though it did and has been written down by Bertrand Meyer. At the same time though, Greg Young and Udi Dahan and some of their fellow Distributed Domain Driven Design guys have been redefining this pattern on the architecture level. You can read about that over here.