Yet another business object design question

Yet another business object design question

Old forum URL: forums.lhotka.net/forums/t/3657.aspx


snesbitt posted on Friday, October 05, 2007

I have read the plethora of threads about Csla object design and normalizing behavior not data, but I can't seem to find an answer to my specific problem.  Any assistance is greatly appreciated ...

I have a Resource object that has a number of properties and validation rules.  And I have a ResourceType object.  All Resource's have one ResourceType.  We are extending the ResourceType object to have a bool property, lets call it IsSpecial, that will enable new functionality on the Resource objects that have this particular ResourceType set.  Lets say that the new functionality will be in the form of two new instance methods A() and B() that only 'special' assigned Resources can use.  The effect of calling A() and B() will be additional logic in the data layer when the Resource is saved.

Resources are assigned to a Reservation via an AssignedResourceList that contains a list of AssignedResource objects.  It is important that all the Resources, regardless of the special property on the ResourceType, are stored in the AssignedResourceList because I have business rules and logic that must act on all Resources.  Therefore, creating a new list object, AssignedResourceSpecialList, is not really an option.

To further complicate the issue, the objects described above are part of a common middle-tier API layer which will be consumed by multiple front-end apps.  One app will utilize the additional functionality, where as the others will not. 

So, as I see it, my design choices include:

1) Define a new object AssignedResourceSpecial that will inherit from AssignedResource and additionally expose A() and B().  By inheriting from AssignedResource I get re-use of the properties and validation rules.  I then override the data access methods to implement A() and B() accordingly.  I also define a readonly collection of AssignedResourceSpecial called AssignedResourceSpecialSummaryList, which allows me to access just the AssignedResourceSpecial objects from the Reservation.  This collection is populated using the data reader that is retrieved when I populate the Reservation.

2) Define a new object AssignedResourceSpecial that will act as a child object of AssignedResource.  The child object will be null if the Resource is not 'special' and not null if it is.  This will allow the additional functionality A() and B() to be exposed for the resource of the particular type.  I then need to put conditional logic in the AssignedResource data methods to implement A() and B() accordingly.  I know these conditional statements is one step closer to spaghetti code, so even though this feels like a nice way of doing it, warning bells are sounding.

I have started down the path of 1) above, but the design is getting a bit messy so I am starting to double-guess myself.  It's clear that the new functionality constitutes new behavior and therefore requires a new business object.  What's not clear to me is how this new object should be implemented in this particular case.  Are there better ways of implementing this new behavior outside of my two descriptions above?

Thanks for reading,

Steve

Copyright (c) Marimer LLC