适配器模式
将各种功能不同的接口封装在一个统一的api中
优点在于,即时在不同的功能中,都可以使用一套api去实现不同的逻辑。
特点:
1:创建是一个可以实现的接口类
2:在这个类中定义好函数方法
代码:
<?php
interface DB{
public function select($id){}
public function update($id){}
public function insert(){}
}
class User implements DB{
/**
* 用户表
**/
public function select($user_id){
return "select * from user where id = {$user_id}";
}
public function update($user_id){
return "update user set level = 2 where id = {$user_id}";
}
public function insert(){}
}
class Order implements DB{
/**
* 订单表
**/
public function select($order_id){
return "select * from order where id = {$order_id}";
}
public function update($order_id){
return "update order set status = 2 where id = {$order_id}";
}
public function insert(){}
}
?>