General use of adapter pattern in PHP

little bottle
Release: 2023-04-05 21:44:02
forward
2504 people have browsed it

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");
Copy after login

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!

Related labels:
source:cnblogs.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template