zoukankan      html  css  js  c++  java
  • AOP-静态代理

    接口类

    <?php
    
    
    namespace AppInterfaces;
    
    
    interface ProductInterface
    {
        public function create($name);
        public function edit($name);
    }
    

     目标类

    <?php
    
    
    namespace AppInterfacesTargets;
    
    
    use AppInterfacesProductInterface;
    
    class Product implements ProductInterface
    {
    
        public function create($name)
        {
            // TODO: Implement create() method.
            echo "目标类创建";
        }
    
        public function edit($name)
        {
            // TODO: Implement edit() method.
            echo "目标类编辑";
        }
    }
    

     代理类

    <?php
    
    
    namespace AppInterfacesProxy;
    
    
    use AppInterfacesProductInterface;
    use AppInterfacesTargetsProduct;
    
    class ProductProxy implements ProductInterface
    {
        private $product;
        /**
         * ProductProxy constructor.
         */
        public function __construct(Product $product)
        {
            $this->product = $product;
        }
    
        public function create($name)
        {
            // TODO: Implement create() method.
            echo "befare
    ";
            $this->product->create($name);
            echo "after
    ";
        }
    
        public function edit($name)
        {
            // TODO: Implement edit() method.
            echo "befare
    ";
            $this->product->edit($name);
            echo "after
    ";
        }
    }
    

     消费者

    /**
         * @RequestMapping(route="product/test",method={RequestMethod::GET})
         */
        public function test(){
            $mb_obj = new AppInterfacesTargetsProduct();
            $pdt_obj = new ProductProxy($mb_obj);
            $pdt_obj->create('张三');
        }
    

      

     

     

  • 相关阅读:
    51nod贪心算法入门-----完美字符串
    HDU6030----矩阵快速幂
    O(n)求1~n的逆元
    (四)添加签到奖励功能
    (三)开始在OJ上添加签到功能
    (二)OJ的主要文件
    (一)在linux上ubuntu搭建hustOJ系统
    CF 148A Insomnia cure
    lower_bound和upper_bound
    C++ string的常用功能
  • 原文地址:https://www.cnblogs.com/finnlee/p/15057142.html
Copyright © 2011-2022 走看看