php的代理模式
<div id="article_content" class="article_content clearfix"><link rel="stylesheet" href="https://csdnimg.cn/release/blogv2/dist/mdeditor/css/editerView/kdoc_html_views-1a98987dfd.css">
<link rel="stylesheet" href="https://csdnimg.cn/release/blogv2/dist/mdeditor/css/editerView/ck_htmledit_views-6e43165c0a.css">
<div id="content_views" class="htmledit_views">
<p>举例,我想去买一张碟片<br> </p>
<pre><code>class client
{
public static function shoping($goods)
{
$poroxy = new proxy;
$poroxy ->buy($goods);
}
}
client::shoping("去英国给我买张CD");</code></pre>
<p>//CD代理</p>
<pre><code>class proxy implements shop
{
public function buy($title)
{
$this->go();
$CDshop = new CDshop;
$CDshop->buy($title);
}
public function go()
{
echo "跑去美国代购".PHP_EOL;
}
}</code></pre>
<p>代理抽象接口</p>
<pre><code>interface shop
{
public function buy($title);
}</code></pre>
<p>跑去了CDshop店里面</p>
<pre><code>class CDshop implements shop
{
public function buy($title)
{
echo "购买成功,这是你的《{$title}》唱片".PHP_EOL;
}
}
</code></pre>
<p></p>
<p></p>
</div>
</div>
<div id="treeSkill"></div>
页:
[1]