<?php /** * Created by PhpStorm. * User: 老鲁 * Date: 2018/3/16 * Time: 21:48 */ class Regitsration { public function regist(Lesson $lesson) { //处理课程 //通知 $notifierObj = Notifier::getNotifier(); $notifierObj->inform(); } } abstract class Notifier { static function getNotifier() { //根据需要和条件设置不同的返回对象 $num = rand(1,2); if ($num == 1) { return new TextNotifier(); } elseif ($num == 2){ return new MailNotifier(); } } } class TextNotifier extends Notifier { public function inform() { return 'TextInform'; } } class MailNotifier extends Notifier { public function inform() { return 'MailInform'; } }
PHP面向对象设计模式-8.2降低耦合示例
最新推荐文章于 2022-11-03 13:29:29 发布