|
Adding Business Rules
Listing 2. Listing 2 adds business rules to the set property in Listing 1. namespace TimeKeeper
{
public class LineItem
{
private DateTime _start;
public DateTime StartTime
{
get
{
return _start;
}
set
{
TimeSpan past = new TimeSpan(-7, 0, 0, 0);
TimeSpan future = new TimeSpan(1, 0, 0, 0);
if (value < DateTime.Now.Subtract(past))
throw new ApplicationException("The start "
+ "date occurs too far in the past.");
else
{
if (value > DateTime.Now.Add(future))
throw new ApplicationException("The start "
+ "date may not occur in the future.");
else
_start = value;
}
}
}
}
}
|