admin 发表于 2023-2-16 18:55:09

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>举例&#xff0c;我想去买一张碟片<br>  </p>
<pre><code>class client

{
      public static function shoping($goods)

      {
            $poroxy &#61; new proxy;
            $poroxy ->buy($goods);

      }

}

client::shoping(&#34;去英国给我买张CD&#34;);</code></pre>
<p>//CD代理</p>
<pre><code>class proxy implements shop
{
    public function buy($title)
    {
      $this->go();
      $CDshop &#61; new CDshop;
      $CDshop->buy($title);
    }
    public function go()
    {
      echo &#34;跑去美国代购&#34;.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 &#34;购买成功&#xff0c;这是你的《{$title}》唱片&#34;.PHP_EOL;
    }
}
</code></pre>
<p></p>
<p></p>
                </div>
      </div>
      <div id="treeSkill"></div>
页: [1]
查看完整版本: php的代理模式