Several of my domain objects contain date ranges as a pair of start and end date properties:
public class Period { public DateTime EffectiveDate { get; set; } public DateTime ThroughDate { get; set; } } public class Timeline { public DateTime StartDate { get; set; } public DateTime EndDate { get; set; } }
And I am with a lot of this:
abstract public int Foo(DateTime startDate, DateTime endDate); abstract public decimal Bar(DateTime startDate, DateTime endDate); abstract public ICollection<C5.Rec<DateTime, DateTime>> FooBar(DateTime startDate, DateTime endDate);
The latter made me wonder ... Should I implement the DateRange class? I do not know about this in BCL.
In my experience, the depth of the hierarchy of objects often complicates the situation. These objects are sent to the RDLC reports displayed by the ReportViewer control, but this is secondary. I will look towards the model, and not vice versa. However, we are not tied to property names and will agree to a compromise with something like:
public class DateRange { public DateTime StartDate { get; set; } public DateTime EndDate { get; set; } } Period p = new Period(); DateTime t = p.EffectiveDateRange.StartDate;
The benefit of the DateRange class will be a centralized confirmation of the end date following the start date, and will simplify my method signatures:
abstract public int Foo(DateRange dateRange); abstract public decimal Bar(DateRange dateRange); abstract public ICollection<DateRange> FooBar(DateRange dateRange);
I'm just not sure that the DateRange class will not make me more worried than its value. Opinions?
Side question: Have I missed the generic generic class of a general-purpose tuple in BCL? I know that in different namespaces there are some very specific ones. The pollution of my public domain method signatures with C5 types is very, very dirty.
quentin-starin Dec 04 '09 at 7:56 2009-12-04 07:56
source share