SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 80 | Next

Hasin Hayder

"Object-Oriented Programming with PHP5"

php
include_once("notifier.php");
class FaxNotifier implements notifier
{
public function notify()
{
//do something to notify the user by Fax
}
}
?>
class.smsnotifier.php
include_once("notifier.php");
class SMSNotifier implements notifier
{
public function notify()
{
//do something to notify the user by SMS
}
}
?>
Now we will use this code:
include_once("EmailNotifier.php");
include_once("FaxNotifier.php");
include_once("SMSNotifier.php");
/**
* Let's create a mock object User which we assume has a method named
* getNotifier(). This method returns either "sms" or "fax" or "email"
*/
$user = new User();
$notifier = $user->getNotifier();
switch ($notifier)
{
case "email":
$objNotifier = new EmailNotifier();
break;
case "sms":
$objNotifier = new SMSNotifier();
break;
case "fax":
$objNotifier = new FaxNotifier();
Design Patterns
[ 70 ]
break;
}
$objNotifier->notify();
?>
I'm sure you'll agree that this is pretty simple. I am also sure that you have already
used such solutions in your existing codes on more than one occasion
Factory Pattern
Another common design pattern is factory pattern. The main goal of this pattern is
delivering an object by hiding all the complexities behind it.


Pages:
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
hotel jelenia góra Russian bride Free English grammar and study guid powiekszenia wielkoformatowe counter strike 1.6