An adaptation allows classes that usually cannot work together because of incompatible interfaces to work together. The adapter pattern is to convert the interface method of a class into another method that I want to use. The code in this article describes a common use of the adapter pattern.
class Session{ public $mc; public function __construct(){ $this->mc=new Memcache(); $this->mc->connect("115.159.28.112"); } //把一个方法转换成另一个方法 public function set($key,$value){ return $this->mc->set($key,$value,MEMCACHE_COMPRESSED,3600); } public function get($key){ return $this->mc->get($key); } } $session=new Session(); $session->set("name","taoshihan"); echo $session->get("name");
Related tutorials: PHP video tutorial
The above is the detailed content of General use of adapter pattern in PHP. For more information, please follow other related articles on the PHP Chinese website!