Domain layer model classes

Oct 5, 2011 at 2:23 AM

I've found Project Silk very useful in helping implement an application consisting of well-decoupled data, business logic, and user interface layers.  However, in implementing my own project, I am trying to decide on the best way to implement inter-object references within the domain model layer. Project Silk seems to use a mixture of explicit object references (for example StatisticsSeries-StatisticsSeriesEntry and VehicleModel-VehicleStatisticsModel) and loosely linked ID-based references (VehicleModel-VehiclePhoto and ReminderModel-ReminderSummaryModel).

Are there any guidelines on when and where to use one or the other style of reference? From a purist viewpoint, I prefer explicit object references.  However, in practice, without lazy loading, this would be inefficient for supporting a range of service handlers that individually may or may not operate across an object graph.

Does anyone have any experience in practice making this design decision?  Is it worthwhile implementing lazy loading in the domain model or is that overkill considering many data layer implementations (EF for instance) will most likely make use of some form of lazy loading at the data-access layer?

Oct 5, 2011 at 4:57 PM


The decision of whether to use an explicit object reference or an indirection such as the one you mentioned depends on your requirements. I believe it's a good practice to achieve loose coupling between your components, especially if you are working in a large project where it is needed to define a clear boundary between your components' responsibilities (which might also be developed in different teams). However, that might include additional complexity in your project, so you should evaluate if the benefits of this approach outweight its costs (in the form of additional complexity).

Also, you should take into account that, by loosely coupling your components between each other, they will be more granular and reusable.

The same applies for lazy loading; in that case, it depends on the resources consumed by the services you will load lazily, compared to the added complexity you will include by doing so.

I hope you find this useful.

Guido Leandro Maliandi