Hello:
A TimeSheetActivity class has a collection of Allocations. An Allocation is a value object that is used by other objects in the domain as well, looking something like this:
public class Allocation : ValueObject
{
public virtual StaffMember StaffMember { get; private set; }
public virtual TimeSheetActivity Activity { get; private set; }
public virtual DateTime EventDate { get ... }
public virtual TimeQuantity TimeSpent { get ... }
}
Duplicate allocations for the same Allocation.EventDate are not allowed. So when a client attempts to make an allocation to an activity, a check is made to see if there is already an Allocation in the collection for the same Allocation.EventDate. If not, then the new Allocation is added to the collection, but if so, the existing Allocation is replaced by the new one.
I am currently using a Dictionary to maintain the collection, with the Allocation.EventDate as the key. It works fine for the domain but I'm wondering if the fact that the key is already part of the value isn't itself a 'bad smell'.
I also have no reason to persist anything but the dictionary values. Because I'm using NHibernate, I may need to write some custom type do that, and I'm wondering if that also is a clue that I should be using a different type of collection. (That's also the reason for the the virtual properties in the Allocation class).
The primary alternative I'm thinking of would be a HashSet with a dedicated EqualityComparer.
What do you think?
Cheers, Berryl