Tuesday, August 12, 2008

When a domain model is not enough

Ever since reading Evans' Domain Driven Design, I have been enamored with the idea of the Domain Model as the keystone of application development. 'Build your domain model first', 'The domain model should receive the most attention', 'Minimize your plumbing (non-domain) code' - These have been my mantra for development the past couple of years.

Recently I have been working on a web framework to present a rich object model via HTML without little or no plumbing code. Constraints and hints would be provided to the framework by applying attributes to the domain classes, providing declarative customization. The generic UI idea has various examples like Naked Objects.

What I am coming to realize through this project is that the Domain Model is not really what you want to present to the user, no matter how clever you are in using conventions to render the model elements in a friendly way. There is inescapably a different shape to the model representing what the user interacts with than the domain model.

To be clear, when I refer to a model I am using the term similarly to Evans. A model, most generally, is a tool for us to think about a problem. Here I refer to design models which are expressed in the software itself.

There are meaningful models present in the design of an application beyond just the domain. If we are talking user applications, there is a Presentation or View Model representing how information is displayed to the user, a Navigation model, and more generally an Interaction or UI Model. Working with these explicitly gives you the advantage of being able to use your big brain to create UI abstractions to make your life easier (as opposed to vilifying your UI). To get cute with terminology, the UI for your application is itself a domain that could benefit from a model.

Hasn't this all been settled with the various UI patterns and the frameworks built around them? Not quite: what is the UI model specific to your application? Could this model help you make your UI code clearer and more effective? Next time I will provide an example from our own application.

No comments: