{ by david linsin }

December 07, 2007

Is your code reflecting a model?

I recently watch a presentation of Eric Evans on Domain Driven Design, where he claims:
A model not reflected in the code is irrelevant
I totally agree on that. However, putting on my developer hat, it got me thinking, if I could reverse this statement and if it would still hold true:
Code not reflecting a model is irrelevant
I guess the answer is, as so often in life, it depends.

First of all I think it depends on what code we are talking about. In this case I'm talking about code that solves some kind of business problem. Think about code of the poster child example: the banking domain. For this kind of code I think the statement hold true. It should reflect the domain model in our code. If it doesn't, the code might not make sense and thus is irrelevant.

There is other kind of code, technical functionality that needs to be implemented. Most of the developers, including myself, love to get our hands dirty and spend countless hours on implementing technical functionality, whereas we should focus on the business problems. Think of something like a StringUtil class. I don't think any code in there reflects a model and if it does, we should have it refactored! Code like that doesn't necessarily need to reflect a domain model, unless your domain is of a technical nature.

This brings me to the second issue that we need to take into account, when validating this statement: the domain itself. I believe it really depends on the domain we develop our code for, if it reflects a model to some extend. The model might not seem obvious, when we are writing code for a non business domain, but there still is something our code reflects. Think of a database driver for instance. It implements a protocol, which I think is a perfect model of the domain we are developing for.

So revising all of my thoughts on this again, I think we can reverse Eric's statement. However I would rephrase my statement and say: Code not reflecting a model is, at least to some extend, irrelevant.



  • mail(dlinsin@gmail.com)
  • jabber(dlinsin@gmail.com)
  • skype(dlinsin)