Sometimes you see some code and can feel the frustration of the original developer. Sometimes it's because of profanity-laden comments in the code, other times it's because you can tell that they were right on the brink of a major breakthrough, but gave up.

In this case from Oliver K., the developer did his research, found the right tools for the job, and started coding. He realized that the task would be best handled with interfaces and probably toiled for hours trying to figure them out, eventually checking in the following:

ISchedule schedule = ScheduleFactory
IScheduledTask nextScheduledTask = null;

if (schedule is DailySchedule)
    nextScheduledTask = ((DailySchedule)schedule)
        .GetNextScheduledTask(startRunTime, true);
if (schedule is WeeklySchedule)
    nextScheduledTask = ((WeeklySchedule)schedule)
        .GetNextScheduledTask(startRunTime, true);
if (schedule is MonthlyByDateSchedule)
    nextScheduledTask = ((MonthlyByDateSchedule)schedule)
        .GetNextScheduledTask(startRunTime, true);
if (schedule is MonthlyByDaySchedule)
    nextScheduledTask = ((MonthlyByDaySchedule)schedule)
        .GetNextScheduledTask(startRunTime, true);
if (schedule is  YearlySchedule)
    nextScheduledTask = ((YearlySchedule)schedule)
        .GetNextScheduledTask(startRunTime, true);
if (schedule is SpecificDatesSchedule)
    nextScheduledTask = ((SpecificDatesSchedule)schedule)
        .GetNextScheduledTask(startRunTime, true);
[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!