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

      

     

     

  • 相关阅读:
    工厂模式
    dubbo
    WebSocket WebService
    消息中间
    原型模式
    ApiPost Apifox
    Future 的使用与源码解析
    JUC 线程池的使用与源码解析
    ReentrantLock 源码解析
    CountDownLatch 的使用与源码解析
  • 原文地址:https://www.cnblogs.com/finnlee/p/15057142.html
Copyright © 2011-2022 走看看