码迷,mamicode.com
首页 > 其他好文 > 详细

适配器模式

时间:2014-07-29 15:47:29      阅读:161      评论:0      收藏:0      [点我收藏+]

标签:private   适配器   return   public   function   

bubuko.com,布布扣

bubuko.com,布布扣


class errorObject {

public $error;

public function __construct ($error){

$this->error = $error;

}

public function getError (){


return $this->error;

}

}

class logToConsole {

private $_errorObject;

public function __construct($_errorObject){

$this->_errorObject = $_errorObject;

}

public function write(){

$fileName = "D:/wamp/www/tc/tc.txt";

$f=fopen($fileName, "a+");

@fwrite($f, $this->_errorObject->getError());

}

}

class logToCsv {

private $_errorObject;

public function __construct ($errorObject){

$this->_errorObject = $errorObject;

}

public function write(){

$line = $this->_errorObject->getNumber();

$line .= ‘,‘;

$line .= $this->_errorObject->getStr();

$line .= ‘\n‘;

fwrite($handle, $line);

}

}

class logToCsvAddpter extends errorObject{

private $_errorNumber;

private $_errortext;

public function __construct($error){

parent::__construct($error);

$part = explode(‘:‘, $this->getError());

$this->_errorNumber = $part[0];

$this->_errortext = $part[1];

$this->_errorObject = $errorObject;

}

public function getNumber(){

return $this->_errorNumber;

}

public function gettext(){

return $this->_errortext;

}

}

$error = new logToCsvAddpter("aaaaaaa");

$log = new logToCsv($error);

$log->write();




本文出自 “php学习” 博客,谢绝转载!

适配器模式,布布扣,bubuko.com

适配器模式

标签:private   适配器   return   public   function   

原文地址:http://xiaochaozi.blog.51cto.com/6469085/1531684

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!