rgb192
asked on
design pattern for a series of tasks
what is a design pattern
$user1= new Instructions($user_name);
$user1->select_rows_of_tab le_in_mysq l($subject , $body, $email_addresses);
$user1->log_in_to_phpmaile r($user_na me);
$user1->send_emails_using_ phpmailer( $user_name );
$user1->insert_phpmailer_e rrors;
and then repeat for $user2, $user3
And then if I wanted to see the data from the table
$user1->see_phpmailer_erro rs($user_n ame) for each user
I think that I am copy pasting too many instances for each task
$user1= new Instructions($user_name);
$user1->select_rows_of_tab
$user1->log_in_to_phpmaile
$user1->send_emails_using_
$user1->insert_phpmailer_e
and then repeat for $user2, $user3
And then if I wanted to see the data from the table
$user1->see_phpmailer_erro
I think that I am copy pasting too many instances for each task
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
>>My feeling though is that a foreach loop on a list of users is the way to go.
>>Repeated tasks in PHP are performed with iterators. Iterators are "control structures," so named because they control the flow of logic in the PHP script. They include foreach() and while()
should this be a factory where everything gets done for each username
because I think that the code will get disorganized with
if for foreach
statements
outside the class
>>Repeated tasks in PHP are performed with iterators. Iterators are "control structures," so named because they control the flow of logic in the PHP script. They include foreach() and while()
should this be a factory where everything gets done for each username
because I think that the code will get disorganized with
if for foreach
statements
outside the class
should this be a factory where everything gets done for each usernamePossibly -- that would seem to make sense, but I can't really know for sure without seeing the data. You would be a better judge of that than I can be.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you for teaching me ways to organize the code.
I will provide more examples soon
I will provide more examples soon
For instance you could have a loop going through a list of users (array or resultset from a database) - for each user found perform the tasks.
If the emails are the same for each user you could simply add all users to the distribution list - and send the mail once but this is only an option if you are sending the same email to everyone and there are no user specific per user settings.
Also depending on what the Instructions object does - you could structure your code either to reuse an existing instance or create a new one for each user.
My feeling though is that a foreach loop on a list of users is the way to go.