I have this problem: let's say that i have a collection of child items, for example an ArrivalSheet that is a collection of ArrivalDetail objects. an ArrivalDetail object represent the Startour and EndHour for a specific Employee(this is a payroll project...), and of course, the date of the arrival to the work.
so i have a tabl like this:
Date StartHour EndHour
1/1/2007 7 AM 4 PM
2/1/2007 7:30 AM 3 PM
...
now, i want to ensure that not 2 ArrivalDetail overides each other, for example, it is not acceptable to say that:
1/1/2007 7 AM 4 PM
1/1/2007 9 AM 2 PM
so, where i can put this validation rule ? i found that it is not good to put this rule in the ArrivalDetail class, because this will make this class responsible for the others in the collection.
I found that i must put this rule in the Collection class, that is in the ArivalSheet. but now the problem is, with what property should this rule be associated ? and when it will be cheked ?
I think this is a common problem in other domains also, for example, if a want to ensure that a Product Name is unique in a collection of Products, where I put this rule ?
Exactly - do it on the list changed.
I have an almost identical situation to yours (mine has to do with date ranges overlapping) - on the listchanged, I cycle through the items as necessary to determine which ones overlap - I then have the collection set an internal setter to indicate on each child that overlaps that it overlaps. I tie a broken rule on each child to this property, so that when displaying a list of the children, it can be flagged which ones are invalid. That is, the ones that overlap.
Copyright (c) Marimer LLC