<?php
interface Cache
{
public function set($key, $value);
public function get($key);
public function delete($key);
}
class Memcache implements Cache
{
public function set($key, $value)
{
// TODO: Implement set() method.
echo $key . '-' . $value;
}
public function get($key)
{
// TODO: Implement get() method.
echo $key;
}
public function delete($key)
{
// TODO: Implement delete() method.
echo $key;
}
}
class CacheFactory
{
public static function factory(Cache $cache)
{
return $cache;
}
}
$cache = CacheFactory::factory(new Memcache());
$cache->set('nihao', 123);