Copy CodeThe code is as follows:
/**
* Adapter Mode
*
* Convert a class's interface into another interface that the customer wants, using classes that are inherently incompatible to work with and can work together
*/
This is the original type.
Class Oldcache
{
Public Function __construct ()
{
echo "Oldcache construct
";
}
Public function Store ($key, $value)
{
echo "Oldcache Store
";
}
Public function Remove ($key)
{
echo "Oldcache remove
";
}
Public function Fetch ($KEY)
{
echo "Oldcache fetch
";
}
}
Interface cacheable
{
Public function set ($key, $value);
Public function get ($key);
Public Function del ($key);
}
Class Oldcacheadapter implements Cacheable
{
Private $_cache = null;
Public Function __construct ()
{
$this->_cache = new Oldcache ();
}
Public function set ($key, $value)
{
return $this->_cache->store ($key, $value);
}
Public function Get ($key)
{
return $this->_cache->fetch ($key);
}
Public Function del ($key)
{
return $this->_cache->remove ($key);
}
}
$objCache = new Oldcacheadapter ();
$objCache->set ("test", 1);
$objCache->get ("test");
$objCache->del ("test", 1);
http://www.bkjia.com/PHPjc/323779.html www.bkjia.com true http://www.bkjia.com/PHPjc/323779.html techarticle Copy the code as follows:? PHP/** * Adapter Mode * * Converts the interface of a class to another interface that the customer wants, using those classes that are inherently incompatible and cannot work together ...