标签:interface after company strong style 对象代理 target err stat
真实对象和代理对象都要实现同一个接口
代理对象代理真实角色
public class staticProxy { interface Marry{ void happyMarry(); } static class You implements Marry{ @Override public void happyMarry() { System.out.println("自己要结婚了!!!"); } } static class WeddingCompany implements Marry{ private Marry target; public WeddingCompany(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("开始布置"); } } public static void main(String[] args) { new WeddingCompany(new You()).happyMarry(); } }
优点:1.代理对象可以做很多真实对象做不了的事情
2.真实对象专注做自己的事情
标签:interface after company strong style 对象代理 target err stat
原文地址:https://www.cnblogs.com/baconZhang/p/13228079.html