一. 开放与封闭原则:
其基本的思想是:
1.Open:模块的行为必须是开放的、支持扩展的而不是难于改变的。
2.Closed:在对模块的功能进行扩展时,不应该影响或大规模地影响原有的程序模块。
二.实例:
<?php
interface process{
public function process();
}
//播放器的编码
class playerEncode implements process{
public function process(){
echo "encode\r\n";
}
}
class playerOutput implements process{
public function process(){
echo "output\r\n";
}
}
//调度管理器
class playProcess{
private $message = null;
public function __construct(){
}
public function callBack(event $event){
$this->message= $event->click();
if ($this->message instanceof process){
$this->message->process();
}
}
}
//播放器的事件处理
class mp4{
public function work(){
$playProcess = new playProcess();
$playProcess->callBack(new event('encode'));
$playProcess->callBack(new event('output'));
}
}
//事件处理类
class event{
private $m;
public function __construct($me){
$this->m = $me;
}
public function click(){
switch($this->m){
case 'encode':
return new playerEncode();
break;
case 'output':
return new playerOutput();
break;
}
}
}
$mp4 = new mp4();
$mp4->work();版权声明:本文为博主原创文章,未经博主允许不得转载。
以上就介绍了(七)面向对象的设计原则之三,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号