When searching recently so as to provide further reading for "domain model" in a recent post, I was quite surprised to find that there seemed to be no good definition readily available (at least not by Googling "domain model"). Since I tend to use this term a lot, I figured I'd try to fill this gap and, at the very least, provide a reference for me to use when I talk about it.
So What is a Domain Model? Put simply, a domain model is the software model of a particular domain of knowledge (is that a tautology?). Usually, this means a business domain, but it could also mean a software domain (such as the UI domain, the data access and persistence domain, the logging domain, etc.). More specifically, this means an executable representation of the objects in a domain with a particular focus on their behaviors and relationships1.
The point of the domain model is to accurately represent these objects and their behaviors such that there is a one-to-one mapping from the model to the domain (or at least as close as you can get to this). The reason this is important is that it is the heart of software solutions. If you accurately model the domain, your solution will actually solve the problems by automating the domain itself, which is the point of pretty much all business software. It will do this with much less effort on your part than other approaches to software solutions because the objects are doing the work that they should be doing--the same that they do in the physical world. This is part and parcel of object-oriented design2.
Nothing New By the way, this is not a new concept--OO theory and practice has been around for decades. It's just that somewhere along the line, the essence of objects (and object-oriented design) seems to have been lost or at least distorted, and many, if not most, Microsoft developers have probably not been exposed to it, have forgotten it, or have been confused into designing software in terms of data. I limit myself to "Microsoft developers" here because it is they of whom I have the most experience, but I'd wager, from what I've read, the same is true of Java and other business developers.
I make this claim because everyone seems to think they're doing OO, but a concrete example of OOD using Microsoft technologies is few and far between. Those who try seem to be more concerned with building in framework services (e.g., change tracking, data binding, serialization, localization, and data access & persistence) than actually modeling a domain. Not that these framework services are not important, but it seems to me that this approach is fundamentally flawed because the focus is on software framework services and details instead of on the problem domain--the business domain that the solutions are being built for.
The Data Divide I seem to write about this a lot; it's on my mind a lot3. Those who try to do OOD with these technologies usually end up being forced into doing it in a way that misses the point of OOD. There is an unnatural focus on data and data access & persistence. Okay, maybe it is natural or it seems natural because it is ingrained, and truly a large part of business software deals with accessing and storing data, but even so, as I said in Purporting the Potence of Process4, "data is only important in as much as it supports the process that we’re trying to automate."
In other words, it is indeed indispensable but, all the same, it should not be the end or focus of software development (unless you're writing, say, a database or ORM). It may sound like I am anti-data or being unrealistic, but I'm not--I just feel the need to correct for what seems to be an improper focus on data. When designing an application, think and speak in terms of the domain (and continue to think in terms of the domain throughout the software creation process), and when designing objects, think and speak in terms of behaviors, not data.
The data is there; the data will come, but your initial object models should not involve data as a first class citizen. You'll have to think about the data at some point, which will inevitably lead to specifying properties on your objects so you can take advantage of the many framework services that depend on strongly-typed properties, but resist the temptation to focus on properties. Force yourself to not add any properties except for those that create a relationship between objects; use the VS class designer and choose to show those properties as relationships (right-click on the properties and choose the right relationship type). Create inheritance not based on shared properties but on shared behaviors (this in itself is huge). If you do this, you're taking one step in the right direction, and I think in time you will find this a better way to design software solutions.
My intent here is certainly not to make anyone feel dumb, stupid, or like they've wasted their lives in building software using other approaches. My intent is to push us towards what seems to be a better way of designing software. Having been there myself, I know how easy it is to fall into that way of thinking and to imagine that simply by using these things called classes, inheritance, and properties that we're doing OOD the right way when we're really not. It's a tough habit to break, but the first step is acknowledging that there is (or at least might be) a problem; the second step is to give object thinking a chance. It seems to me that it is (still) the best way to do software and will continue to be in perpetuity (because the philosophical underpinnings are solid and not subject to change).
Notes 1. An object relationship, as I see it, is a special kind of behavior--that of using or being used. This is also sometimes represented as a having, e.g., this object has one or more of these objects. It is different from data because a datum is just a simple attribute (property) of an object; the attribute is not an object per se, at least not in the domain model because it has no behaviors of its own apart from the object it is attached to. It is just information about a domain object.
2. I go into this in some depth in the Story paper in the Infragistics Tangerine exemplar (see the "To OOD or Not to OOD" section). I use the exemplar itself to show one way of approaching domain modeling, and the Story paper describes the approach.
3. Most recently, I wrote about this in the Tangerine Story (see Note 2 above). I also wrote publicly about it back in late 2005, early 2006 in "I Object," published by CoDe Magazine. My thought has developed since writing that. Interestingly, in almost two years, we seem to have only gotten marginally better ways to deal with OOD in .NET.
4. In that article, I put a lot of focus on "process." I still think the emphasis is valid, but I'd temper it with the caveat that however business rules are implemented (such as in the proposed workflow-driven validation service), you still think of that as part of your domain model. The reason for separating them into a separate workflowed service is a compromise between pragmatism and idealism given the .NET platform as the implementation platform. I've also since learned that the WF rules engine can be used apart from an actual .NET workflow, so depending on your application needs, just embedding the rules engine into your domain model may be a better way to go than using the full WF engine. If your workflow is simple, this may be a better way to approach doing validation.
The opinions expressed herein are solely my own personal opinions, founded or unfounded, rational or not, and you can quote me on that.
Thanks to the good folks at dasBlog!
Copyright © 2017 J. Ambrose Little