J. Ambrose Little

Communicating Infragistics, .NET, Java, and related technologies.
Object Thinking Domain Model Example

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:
Click to See Full Event Calendar 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.

Notes
1. 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.

Posted: 01 Oct 2007, 17:03

Comments

Roland Rodriguez said:

Hi there,

Read the book Object Thinking (based on your recommedation in the Story doc, thanks!).  Wondering if this diagram needs to call out the collection objects as individual objects as well?  For example between Calendar and Events there is a method on the Calendar object called GetEvents.  This indicates the existence of an Events object which would have it's own behaviours regarding the aggregation of Event objects.

What are your thoughts on those being visible in a domain model or are they simply implied since we don't care about cardinality in these types of diagrams?

Regards,

Roland

# January 7, 2008 2:35 PM

J. Ambrose Little said:

Hi Roland,

It would be nice if the VS class diagram could handle method return types like it handles properties--allowing them to be shown as relationships.  It doesn't.  I think I may have just used a generic List there, anyways, but FxCop recommends creating custom collection types derived from Collection<T> (IIRC), so yeah, I'd show that here if it had interesting behavior.  Probably wouldn't show it, though, if it was just meeting the requirements/recommendations of the platform (as would likely be the case here).

It's not a perfect diagramming tool, especially w/o annotations as this image is.  I usually finish my diagrams with annotations to elucidate the dark areas, and I use XML comments to do the same verbally in the API itself.  If you had this loaded in VS, you could see those (if you were studious enough).  

Anyways, the nice thing is that this DSL leaves you with the shell of your domain model already implemented.  If I had my druthers (read: time/resources), I'd write my own DSL that would handle better modeling and also generate a lot of the boilerplate stuff to play nice in .NET.

# January 7, 2008 4:59 PM
Leave a Comment

(required) 

(required) 

(optional)

(required) 

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS