• JAVA Spring5静态代理


    Spring的静态代理

    1、可以使真实角色操作更纯粹不用去关心一些公共业务

    2、公共业务交给代理角色! 实现了业务分工

    3、业务发生拓展的时候,方便集中管理

     

    被代理的类
    package com.chirs.Demo;

    public class Host implements RentInterface {
       public void Rent() {
           System.out.println("房东要租房子");
      }
    }

     

    代理类
    package com.chirs.Demo;

    public class Proxy implements RentInterface {

       private Host host;

       public Proxy() {
      }

       public void setHost(Host host) {
           this.host = host;
      }

       public Proxy(Host host) {
           this.host = host;
      }

       public void Rent() {
           SeeHourse();
           host.Rent();
           HeTong();
           ShouFei();
      }

       public void SeeHourse() {
           System.out.println("带看房");
      }

       public void HeTong() {
           System.out.println("签合同");
      }

       public void ShouFei() {
           System.out.println("收钱");
      }
    }

     

    测试类
    import com.chirs.Demo.Host;
    import com.chirs.Demo.Proxy;
    import com.chirs.Demo.RentInterface;

    public class myTest1 {
       public static void main(String[] args) {
           Host host  = new Host();
           Proxy proxy = new Proxy();
           proxy.setHost(host);
           proxy.Rent();
      }
    }

     

    
    
  • 相关阅读:
    SmartJS 系列规划分享和背景介绍
    SmartJS 第一期(0.1)发布
    让文档和Demo生成更加简单和强大
    SmartDoc(YUIDoc) 注释编写
    smartjs
    smartjs
    smartjs 0.3 DataManager 发布&介绍
    smartjs 0.2 OOP讲解
    smartjs 0.2 OOP讲解
    smartjs 0.2发布
  • 原文地址:https://www.cnblogs.com/wooroc/p/13553785.html
Copyright © 2020-2023  润新知