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('张三');
        }
    

      

     

     

  • 相关阅读:
    快速幂模板
    部分有关素数的题
    POJ 3624 Charm Bracelet (01背包)
    51Nod 1085 背包问题 (01背包)
    POJ 1789 Truck History (Kruskal 最小生成树)
    HDU 1996 汉诺塔VI
    HDU 2511 汉诺塔X
    HDU 2175 汉诺塔IX (递推)
    HDU 2077 汉诺塔IV (递推)
    HDU 2064 汉诺塔III (递推)
  • 原文地址:https://www.cnblogs.com/finnlee/p/15057142.html
Copyright © 2011-2022 走看看