XAF - 1 - Best practices for domain objects

XAF Team Blog
20 May 2008

This is post no. 1 in the mini series "10 exciting things to know about XAF". You can find the announcement of the series here.

This post is not so much about ways of creating good domain object hierarchies. Of course this is an important and interesting topic, but it is also vastly complex and can't really be handled in a one-off blog post. We have plans to provide much more material on this in the next few months, but for the time being let me just point you to two useful books:

The second book brings me closer to the main topic of this post. Our Object/Relational Mapping XPO currently forms the basis of data persistence in XAF. A lot of the architectural decisions in XPO were made after a close look at Fowler's P of EAA, so if you read it, you will recognize many of the ideas.

When you start implementing your own business class hierarchy on top of XPO, there's certainly a lot you can do "wrong". Part of the problem is perhaps that "wrong" doesn't mean it won't work at all, it merely means that somebody with more experience would have used a different approach -- you will figure it out eventually, but by that time it might require significant effort to change things.

As a starting point, we have a list of best practices in our Knowledge Base. I suggest you read this and follow the links from the article, as they point to more important content. Here's a list of other articles you shouldn't miss:

  • XPO Simplified property syntax - a summary
    An explanation of the different ways of implementing properties in persistent classes, including pros and cons
  • http://documentation.devexpress.com/#XPO/CustomDocument3311
    A summary of the differences between the base classes in the XPO distribution. XAF comes with the BaseObject class in addition to the standard XPO ones, which is derived from XPCustomObject and implements a Guid as the primary key.
  • Session Management and Caching
    Lots of details about the way the Identity Map object cache works in XPO, how session management influences it, and what else you can do to improve efficiency through caching on the data layer
  • How the XPO cache works
    A summary of information from the previous article, as it pertains to the Identity Map object cache in XPO
  • XPO - Transaction support
    Details on the UnitOfWork, XPO's most important class related to transaction handling

The questions of where to put your business logic, and from where to execute it (yes, these are two different questions!) are also very important. We need to provide more content on this, but here are my personal rules of thumb in a nutshell:

  1. BL that affects only one class should live in that class.
  2. BL that affects more than one class shouldn't live in either of the affected classes. In XAF, we have controller classes that can be an adequate place for such logic, but as these controllers are tightly bound to the idea of making funtionality available in the UI, they are not the "cleanest" place to use and they complicate unit and functional testing as well. In the future, workflows will provide a new place for cross-class BL to be implemented, meanwhile a number of separate "BL controller" classes, probably one per functional area, is the best idea.
  3. For the specific BL area of rules and validation, our XAF Validation module offers a useful platform. This will be subject of further discussion later in this series.
  4. Calls into business logic should not be triggered from business objects themselves. It's almost always a bad idea to react to events like "AfterSave" and execute business logic in response.

A further interesting read on this topic is my article My persistent classes are real classes. Or not?

Right, that's it for now. I hope it's useful!

Free DevExpress Products - Get Your Copy Today

The following free DevExpress product offers remain available. Should you have any questions about the free offers below, please submit a ticket via the DevExpress Support Center at your convenience. We'll be happy to follow-up.
No Comments

Please login or register to post comments.