I have two ideas on how to proceed with an availability class but I'm not sure which one is better.
public class TimeRange {
private Timestamp startTime;
private Timestamp endTime;
public TimeRange() {
//set defaults
}
// appropriate getters
//setters
public void setStartTime(Timestamp startTime) {
this.startTime = startTime;
}
public void setEndTime(Timestamp endTime) {
this.endTime = endTime;
}
// some code that validates the object is in a valid state.
}
First Idea:
public class WeeklyAvailabilities {
private TimeRange mondaySlot;
private TimeRange tuesdaySlot;
private TimeRange wednesdaySlot;
private TimeRange thursdaySlot;
private TimeRange fridaySlot;
private TimeRange saturdaySlot;
private TimeRange sundaySlot;
public WeeklyAvailabilities() {
// set defaults
}
// some getters and such
public void setMondayStartTime(Timestamp start) {
mondaySlot.setStartTime(start);
}
public void setMondayEndTime(Timestamp end) {
mondaySlot.setEndTime(end);
}
// continue the pattern for all the slots
}
Second Idea:
public class WeeklyAvailabilities {
private TimeRange mondaySlot;
private TimeRange tuesdaySlot;
private TimeRange wednesdaySlot;
private TimeRange thursdaySlot;
private TimeRange fridaySlot;
private TimeRange saturdaySlot;
private TimeRange sundaySlot;
public WeeklyAvailabilities() {
// set defaults
}
// some getters and such
public void setMondaySlot(TimeRange mondaySlot) {
this.mondaySlot = mondaySlot;
}
// continue the pattern for all the slots
}
I'm conflicted due to the fact that the first idea doesn't require a new object to be created every time while the second idea would require something of the sort. Really just wondering if I could have some input on which one is better, or if there might be a third option that I'm completely overlooking.
TimeRange
an immutable object, with a constructor taking two arguments. Otherwise, you always have to worry about the case where start is after stop.