zoukankan      html  css  js  c++  java
  • 静态代理的实现-模拟中介代理房东出租房子给房客

    package com.hpy.test;
    
    /**
     * 房东
     */
    public interface Landlord {
        public void house();
    }
    package com.hpy.test;
    
    /**
     * 房东A
     */
    public class LandlordA implements Landlord{
        public void house(){
            System.out.println("房东A出租美丽沙三室一厅房子");
        }
    }
    package com.hpy.test;
    
    /**
     * 房东B
     */
    public class LandlordB implements Landlord {
        public void house(){
            System.out.println("房东B出租西海岸三室一厅房子");
        }
    }
    package com.hpy.test;
    
    /**
     * 中介
     */
    public class Intermediary implements Landlord {
        private Landlord landlord;
        public Intermediary(Landlord landlord){
            this.landlord = landlord;
        }
    
        @Override
        public void house() {
            landlord.house();
        }
    }
    package com.hpy.test;
    
    /**
     * 房客
     */
    public class Client {
        public static void main(String[] args) {
          new Intermediary(new LandlordA()).house();
          new Intermediary(new LandlordB()).house();
        }
    }

    控制台打印:

              

  • 相关阅读:
    【html、CSS、javascript-9】jquery-选择器及过滤器
    【python之路40】Python 作用域
    H5缓存
    解决网络不可用--Using_Service_Workers
    跨域请求CORS
    基于node的websocket示例
    test
    函数节流
    ES6 promise
    web前端免费资源集
  • 原文地址:https://www.cnblogs.com/ithfm/p/9565512.html
Copyright © 2011-2022 走看看