Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 159019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T10:47:05+00:00 2026-05-11T10:47:05+00:00

Please help me to implement Factory design pattern for the task. I working on

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T10:47:06+00:00Added an answer on May 11, 2026 at 10:47 am

    You could create a wrapper object for the scheduling options and pass that along with the type to the SchedulerFactory.create() method. In your factory method you would then create scheduler objects and set properties based on the types so everything is encapsulated in the Scheduler Factory. I suppose you could also do something messy and use PHP’s variable method arguments instead of an object but that would get ugly.

    I would avoid creating a setOptions method as this would require an instance of SchedulerFactory where passing the options as an object allows the factory (and create method) to remain static.

    To add to vartec’s post, since it appears from your design and use of the Factory pattern the Scheduler subclass properties are only read after the objects are created, you may want to make each Scheduler immutable by allowing the properties to only be set at the time the object is created (in the constructor).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 86k
  • Answers 86k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The simplest thing to do is: Foorecord = #my_record{foo=proplists:get_value(foo, Keyvalpairs),… May 11, 2026 at 5:24 pm
  • Editorial Team
    Editorial Team added an answer Take a look at Detours, it's perfect for this sort… May 11, 2026 at 5:23 pm
  • Editorial Team
    Editorial Team added an answer I had similar thoughts developing my own CMS engine. Eventually… May 11, 2026 at 5:23 pm

Related Questions

Concerning headers in a library, I see two options, and I'm not sure if
I am new to Swing and wish to implement the download file feature in
I have been trying to encrypt soap message and send to the server, so
Okay, I have ran in to a problem with VB.NET. So all those defenders

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.