zoukankan      html  css  js  c++  java
  • 设计模式 之 代理模式

    简单的静态代理,老实说我没觉得和装饰器模式有啥不同,就是组合组合组合

    package com.test.pattern.proxy;
    
    //subject 抽象主题 定义主要功能
    interface Subject {
        public void operation();
    }
    
    //realsubject 具体主题
    class Realsubject implements Subject {
    
        public void operation() {
            System.out.println("realsubject operation started.");
        }
    }
    
    //Proxy
    class Proxy implements Subject {
        private Subject subject;
        public Proxy(Subject subject) {
            this.subject=subject;
        }
        public void operation() {
            System.out.println("proxy fronties operation.");
            subject.operation();
            System.out.println("proxy end operation.");
        }
    }
    public class Client {
        public static void main(String[] args) {
            Subject subject = new Realsubject();
            Proxy proxy = new Proxy(subject);
            proxy.operation();
        }
    }
  • 相关阅读:
    Oracle 操作数据库(增删改语句)
    web----框架基础
    js----DOM对象
    易错之for循环
    python调用修改变量新方法
    js----基础
    web----Twisted
    web----Socket
    python----面向对象(2)
    python----面向对象
  • 原文地址:https://www.cnblogs.com/heben/p/5782836.html
Copyright © 2011-2022 走看看