CopyCode The Code is as follows: <? PHP
/**
* Adapter Mode
*
* Convert an interface of a class to another interface that the customer wants. classes that are originally incompatible and cannot work together can work together.
*/
// This is the original type
Class oldcache
{
Public Function _ construct ()
{
Echo "oldcache construct <br/> ";
}
Public Function store ($ key, $ value)
{
Echo "oldcache store <br/> ";
}
Public Function remove ($ key)
{
Echo "oldcache remove <br/> ";
}
Public Function fetch ($ key)
{
Echo "oldcache fetch <br/> ";
}
}
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 );