适配器

<?php
/**
* Created by PhpStorm.
* User: ytron123
* Date: 18/3/23
* Time: 下午3:46
*/
class err{
private $err;
public function __construct($err){
$this->err = $err;
}
public function getErr(){
return $this->err;
}
}
class fileErr{
private $errObj;
public function __construct(err $obj){
$this->errObj = $obj;
}
public function intoErr(){
$data = $this->errObj->getErr();
echo $data;
}
}
//$obErr = new err('错误信息|21212');
//$obFile = new fileErr($obErr);
//$obFile->intoErr();
//echo '<hr />';
/////实现适配
class newErr extends err{
private $err;
private $errMsg;
private $errCode;
public function __construct($errData){
parent::__construct($errData);
$data = explode('|',$this->getErr());
$this->errMsg = $data[0];
$this->errCode = $data[1];
}
public function getErrMsg(){
return $this->errMsg;
}
public function getErrCode(){
return $this->errCode;
}
}
class newfileErr{
private $errMsg;
public function __construct(newErr $obj){
$this->errMsg = $obj;
}
public function newIntoErr(){
echo $this->errMsg->getErrCode();
echo $this->errMsg->getErrMsg();
}
}
$obNewErr = new newErr('错误信息|21212');
$obNewFile = new newfileErr($obNewErr);
$obNewFile->newIntoErr();

 


posted on 2018-03-23 16:21  我很迷茫  阅读(270)  评论(0编辑  收藏  举报