<?php $reg = new RegistrationMgr(); $reg->register(new Lecture(4, new FixedCostStrategy())); $reg->register(new Seminar(5, new TimedCostStrategy()));
static function getNotifier() { // acquire concrete class according to // configuration or other logic if (rand(1, 2) == 1) { return new MailNotifier(); } else { return new TextNotifier(); } } abstract function inform($message); } class MailNotifier extends Notifier { function inform($message) { print "MAIL notification: {$message}\n"; } } class TextNotifier extends Notifier { function inform($message) { print "TEXT notification: {$message}\n"; } } $lessons1 = new Seminar(4, new TimedCostStrategy()); $lessons2 = new Lecture(4, new FixedCostStrategy()); $mgr = new RegistrationMgr(); $mgr->register($lessons1); $mgr->register($lessons2);