one. Open and closed principles:
The basic idea is:
1. Open: The behavior of the module must be open, support expansion, and not be difficult to change.
2.Closed: When extending the functions of the module, the original program module should not be affected or affected on a large scale.
2. Example:
<?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();
Copyright Statement: This article is an original article by the blogger and may not be reproduced without the blogger's permission.
The above has introduced the third principle of (7) object-oriented design, including aspects of content. I hope it will be helpful to friends who are interested in PHP tutorials.