A few 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 find myself 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 last one made me wonder ... Should I implement a DateRange class? I'm not aware of one in the BCL.
In my experience, making the object hierarchy deeper often complicates things. These objects do get sent to RDLC reports displayed by the ReportViewer control, but that's secondary. I'll bend the view to the model rather than vice versa. We aren't tied to the property names, though, and would be willing to 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;
A benefit of a DateRange class would be centralized validation of the end date coming after the start date, and it 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 a DateRange class won't get me into more trouble than its worth. Opinions?
Side question: Did I miss a generic general-purpose tuple class in the BCL somewhere? I know there's some very specific ones floating around in various namespaces. Polluting my public domain method signatures with C5 types feels very, very dirty.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…