Please help me to implement Factory design pattern for the task.
I working on scheduled message sending web application. User can specify his own scheduled sending plan, and messages will be delivered when it have to. User can choose only one of 3 reccuring types: monthly, weekly, daily. For this 3 reccuring types algorithm is similar: 1) choose send date and time(for first delivery) 2) choose option in "repeat every X months/weeks/days" depending on reccuring type 3) specify end by type(date or by occurences limit)
Weekly scheduler is a little bit different. It has one more feature - week days for repeating(ex: repeat every Mon, Fri)
class SchedulerFactory {
public function create($type) {
switch ($type) {
case "monthly" :
$Scheduler = new MonthlyScheduler();
break;
case "weekly" :
$Scheduler = new WeeklyScheduler();
break;
case "daily":
$Scheduler = new DailyScheduler();
break;
default:
return null;
}
}
}
Setter methods:
$SendScheduler->setSendDateAndTime("{$day}.{$month}.{$year}", time());
switch($end_by_type) {
case 'by_date':
$SendScheduler- >setEndByDate("{$end_by_date_day}.{$end_by_date_month}.{$end_by_date_year}");
break;
case 'by_occurences_limit':
$SendScheduler->setOccurencesLimit($occurences_quantity);
break;
}
$SendScheduler->addTaskOccuringEvery($RepeatEveryMonth);// repeat every X months/weeks/days depending on type
// only for weekly type
$SendScheduler->setWeekDayForRepeating($week_day); // repeat every Mon, Fri
I want to use Factory pattern for object construction(Is it the best match?), and don't know how can I pass all this parameters(not just $type, but all other) for object construction.
Should I create wrap them in single data object, and create method "setOptions" in the SchedulerFactory class and pass this data object to "create" construction method through getter?
Maybe creating of such setter method in Factory class is violation of Factory design pattern principles? I didn't see an examples like this before, so I'm a bit confused now.
If I'm going in absolutely wrong direction, please let me know. What solution would you recommend for this task?
Thanks, in advance