设计模式PHP篇(三)————适配器模式

简单的适配器模式:


interface Adaptor
{
	public function read();
	public function write();
}

class File implements Adaptor
{
	public function write()
	{
		echo "file write" . PHP_EOL;
	}

	public function read()
	{
		echo "file read" . PHP_EOL;
	}
}

class DB implements Adaptor
{
	public function write()
	{
		echo "db write" . PHP_EOL;
	}

	public function read()
	{
		echo "db read" . PHP_EOL;
	}
}


class Client
{
	public function call($obj)
	{
		$obj->read();
		$obj->write();
	}
}

$client = new Client();
$client->call(new File());
$client->call(new DB());

posted @ 2017-06-26 11:01  秦至臻  阅读(150)  评论(0编辑  收藏  举报