zoukankan      html  css  js  c++  java
  • 23种设计模式学习之代理模式

    被代理接口

    public interface Source {
         void method1();
    }
    

     被代理对象

    public class SourceImpl implements Source {
        @Override
        public void method1() {
            System.out.println("2");
        }
    }
    

     代理对象

    public class Proxy implements Source {
        private SourceImpl source;
    
        public Proxy() {
            this.source = new SourceImpl();
        }
    
        @Override
        public void method1() {
            before();
            source.method1();
            after();
        }
        private void before(){
            System.out.println("before");
        }
        private void after(){
            System.out.println("after");
        }
    }
    

     实例

    public class Demo {
        public static void main(String[] args) {
            Source source =new Proxy();
            source.method1();
        }
    }
    
  • 相关阅读:
    菜根谭#317
    菜根谭#316
    菜根谭#315
    菜根谭#314
    菜根谭#313
    菜根谭#312
    菜根谭#311
    菜根谭#310
    菜根谭#309
    Matlab xpC启动盘
  • 原文地址:https://www.cnblogs.com/2nao/p/8296741.html
Copyright © 2011-2022 走看看