I'm going to try come up with an example that I think is simple enough to cover but complex enough to show off some of the issues you are likely to face whilst trying to do DDD with NHibernate.

I'll thus use a simple Customer/Order example, based somewhat on the Order Archetype described in the Archetype Patterns book (simplified massively). I’m assuming that the system is being developed for a small specialist computer bookstore working in the UK.

Although I’m going to base the solution slightly on an archetype I’m not suggesting that I believe that MDA is the way to go, I do however believe the models in the book are useful and they give me something to work with in this example. The classes involved in this simplified example are:
  1. Customer - A slimmed down representation of any individual (ignore organizations for now) who has purchased from us.
  2. MarketingGroup - We group Customers into MarketingGroups and some systems use these groups when deciding how to deal with the issue of marking to the Customer.
  3. Order - An Order will contain one or more OrderLines and each order line has to move through multiple lifecycle states.
  4. OrderLine - Represents the part of an Order that is a summary of particular goods or services ordered by a buyer.
  5. Agent - Someone who introducers a Customer to the company and then handles any communication with them, if the Customer came directly to us then they will have no Agent.
  6. Name - Contains a persons name.
  7. Address - We need to manager the addresses of all of our Customers.
  8. BankAccount - We will record this information for all Customers.
  9. Money - Since the system will need to track the cost of items that Customers are buying we will have a class used to represent money.

You might think I’ve kept my domain too simple but it is just a starting point and I think it should be enough to show some of the practical technical issues you meet when doing DDD though.

Although I'm using the archetype as a strarting point I'll also use TDD. Personally I find this is the way TDD works best, start with a high level design and use TDD/refactoring to improve it. Evans covers this topic superbly in the chapter "Model-Driven Design", describing the balance you have to draw between finding a single model that reflects domain ideas and design principles.

Last edited Aug 27, 2007 at 3:02 PM by colin_jack, version 3

Comments

No comments yet.