Log in to like this post! Object Thinking Domain Model Example Ambrose Little / Monday, October 1, 2007 Previously, I mentioned I was working on an example of using Visual Studio to create a concrete domain model using object thinking, and here it is. The domain I ended up modeling was that of a shared event calendar, including event registration and agenda planning. This is something that's been kind of rolling in and out of my mind for quite a while now because it seems that we need a good system for this for all the code camps and like events that occur. Of course, lately I've come across a few solutions that are already built1, but it seemed like a domain I knew enough about that I could take a whack at modeling it on my own. I also figured it was small enough in scope for a sample. So without further ado, I present you with the domain model: I put this together in about an hour, maybe an hour and a half, on the train up to SD Best Practices. When I started out modeling it, I was actually thinking more generally in the context of a calendar (like in Outlook), but I transformed the idea more towards the event planning calendar domain. So you see some blending of an attendee being invited to a meeting with the event planning objects & behaviors (agenda, speaker, etc.). Interestingly, they seem to meld okay, though it probably needs a bit of refactoring to, e.g., have an Attendee Register(Person) method on the Event object. So the interesting thing to see here, contrasting it to the typical model you see in the .NET world (if you're lucky enough to see one at all!), is that there is pretty much no data, no simple properties or attributes, in the model. The model is entirely objects and their behaviors and relationships to other objects. You can look at this model and get a pretty darn good feel for the domain and also how the system functions as a whole to serve this domain. I was able to identify and model the objects without once thinking about (and getting distracted with) particular data attributes.2 In the story of our Tangerine project, I describe in some depth the compromise I had to make with the .NET framework when it comes to data properties. I think if I were to continue with this event calendar project, after I had nailed down the objects based on their behaviors (as begun in this example) and felt pretty good that it was spot on, at that point, I'd think about the data and do something like I did on Tangerine, having the open-ended property bag but also adding strongly-typed properties as needed to support framework tooling.3 I hope you can imagine how you could sit with your clients or whoever your domain experts are and quickly map out a lightweight model of the domain using the VS Class Designer DSL. I'll wager that if we took this diagram and showed it to a non-technical person, with a little help (maybe adding a key/legend), they'd quickly understand what's going on with the system. And if you're building it with the domain expert, you'll have that dialog done already so that everyone will be on the same page. Sure, there will be further refinement of both the domain model and the code; the nice thing about using the class designer DSL is that tweaking the model tweaks the code, so the two stay in sync. We already mentioned the need to focus on the data at some point, and depending on your situation, you can do this with the domain experts or maybe you'll have an existing data model to work with. As the developer, you're going to want to get in there and tweak the classes and methods to use best coding and framework practices, things that aren't best expressed in such a model. You will have other concerns in the system to think about like security, performance, logging, user interface, etc., but that's all stuff you need to do regardless of how you approach analyzing and modeling your domain. In the end, you will have a fairly refined model of the domain (or part of the domain) that is using a language that everyone gets and agrees on (Eric Evan's "ubiquitous language"); you'll have identified the objects in the domain accurately based on their behaviors and relationships, and you'll even have a starting point in code for the implementation. You also have objects that are responsible and that collaborate to get the job done, so in that way you avoid code complexity by reducing imperative control constructs. All in all, it seems like a great foundation upon which to build the software. Notes1. Such as Microsoft Group Events, Community Megaphone, and Eventbrite.2. Okay, so maybe I was tempted once or twice, but I fought the urge. :) 3. I suppose another option would be to create LINQ-based DTOs; I have to think more about how best to meld this kind of domain modeling with LINQ.