简单的适配器模式:
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());