package com.xiao.StacticProxy; //静态代理模式总结: //真实对象和代理对象都要实现同一个接口 //代理对象要代理真实角色 //好处:代理对象可以做很多真实对象做不了的事情 //真实对象专注做自己的事情 public class demo { public static void main(String[] args) { // new Thread(xxx).start();对比下面的代码 Lili lili = new Lili(new You()); lili.HappyMarry(); } } interface Marry{ void HappyMarry(); } class You implements Marry{ @Override public void HappyMarry() { System.out.println("兵兵要结婚了,超开心"); } } class Lili implements Marry{ private Marry target; public Lili(Marry target){ this.target=target; } @Override public void HappyMarry() { before(); this.target.HappyMarry(); after(); } private void after() { System.out.println("收尾款"); } private void before() { System.out.println("布置现场"); } }
微信扫码关注
更新实时通知