PHP设计模式之简单投诉页面实例
本文实例介绍了PHP简单投诉页面的实现代码,分享给大家供大家参考,具体内容如下 php代码: /*
interface DB { function conn(); /**
protected static $_instance = NULL; public static function getInstance() { final protected function __construct() { final protected function __clone() { public function conn() { } /**
function createDB(); class MysqlFactory implements Factory { public function createDB() { } /**
protected $_observers = NULL; public function __construct($style) { public function show() { public function attach(SplObserver $observer) { public function detach(SplObserver $observer) { public function notify() { } class StyleA implements SplObserver { public function update(SplSubject $subject) { } class StyleB implements SplObserver { public function update(SplSubject $subject) { } /**
protected $_obj = NULL; public function __construct($obj) { public function msg($type) { } public function show() { } class BridgeEmail extends Bridge { public function msg() { } class BridgeSms extends Bridge { public function msg() { } class Normal { public function msg() { } class Danger { public function msg() { } /**
public $content = NULL; public function __construct($content) { public function show() { } class JsonAdapter extends Serialize { public function construct($content) { public function show() { } /**
protected $_content = NULL; public function __construct($content) { public function getContent() { } class Decorator { private $_base = NULL; public function __construct(Base $base) { public function show() { } /**
protected $_level = 1; public function deal($level) { } class level2 { protected $_level = 2; public function deal($level) { } class level3 { protected $_level = 3; public function deal($level) { } if (!empty($_POST)) { PHP设计模式';//连接数据库——工厂+单例模式 $mysqlFactory = new MysqlFactory(); $single = $mysqlFactory->createDB(); $single->conn(); echo ' '; //观察者模式 $username = $_POST['username']; $ob = new Observer($username); $a = new StyleA(); $ob->attach($a); $b = new StyleB(); $ob->attach($b); $ob->show(); echo ' '; $ob->detach($b); $ob->show(); echo ' '; //桥接模式 $typeM = $_POST['typeM']; $typeN = 'Bridge' . $_POST['typeN']; $obj = new $typeN(new $typeM); $obj->show(); echo ' '; //适配器模式 $post = $_POST; $obj = new Serialize($post); echo $obj->show(); echo ' '; $json = new JsonAdapter($post); echo $json->show(); echo ' '; echo ' '; //装饰器模式 $content = $_POST['content']; $decorator = new Decorator(new Base($content)); echo $decorator->show(); echo ' '; //责任链模式 echo ' '; $level = $_POST['level']; $deal = new Level1(); $deal->deal(intval($level)); return; } require("0.html"); html代码: 以上就是本文的全部内容,希望对大家的学习有所帮助。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |