News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

PHPMaster.com:
Understanding the Command Design Pattern
January 03, 2012 @ 08:25:29

On PHPMaster.com today there's a new article introducing you to the Command design pattern and looking to help you understand its use a bit better.

The majority of [cell phone] users have opted to receive an email, but a significant number are now opting to receive the notifications via SMS. Here's the problem: How do you send a message via two different channels to both groups of users? The logical approach would be to split the users into 2 groups, email recipients and SMS recipients, which would involve running 2 different queries and sending the codeword to each group separately. Using the Command Pattern, which I will introduce you to in this article, you can send the message to both groups of users in a single process.

He uses the message queue he mentioned as an example - showing how you can can queue up different kinds of objects (actions) based on a common interface into the same process. He creates a "DailyAlertEmail" and "DailyAlertSMS" classes, both with a "send" method. The settings for these are then pulled from a database and the "execute" method on the "MessageQueue" class is called to loop through them, calling "send" to do that work.

0 comments voice your opinion now!
command designpattern tutorial message queue sms email


blog comments powered by Disqus

Similar Posts

Tobias Schlitt's Blog: A Two-day Look at PHPWeekender

Aleksey Martynov's Blog: Getting started with lexa-tools: Blog in 15 Minutes

Freek Lijten's Blog: Git commit hooks using PHP

CSS-Tricks.com: Tracking Clicks, Building a Clickmap with PHP and jQuery

ThinkPHP Blog: Methods to Reduce the Load of Your Webserver by Caching Content


Community Events





Don't see your event here?
Let us know!


podcast release framework symfony2 series testing experience language list install interview threedevsandamaybe developer code unittest laravel community opinion introduction refactor

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework