代理模式 Posted on 2021-02-25 | In 设计模式 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364public interface IGamePlayer { public void killBoss(); public void upGrade();}public class GamePlayer implements IGamePlayer{ private String name; public GamePlayer() { } public GamePlayer(String name) { this.name = name; } @Override public void killBoss() { System.out.println("打怪"); } @Override public void upGrade() { System.out.println("升级"); }}public class GamePlayerProxy implements IGamePlayer{ private IGamePlayer player = null; public GamePlayerProxy(IGamePlayer player){ this.player= player; } private void log(){ System.out.println("打怪 时间 " + new Date().toString()); } @Override public void killBoss() { System.out.println("打怪前"); player.killBoss(); System.out.println("打怪后"); } @Override public void upGrade() { }}public class Client { public static void main(String[] args) { GamePlayer gamePlayer = new GamePlayer("李逍遥"); GamePlayerProxy gamePlayerProxy = new GamePlayerProxy(gamePlayer); gamePlayerProxy.killBoss(); }} Donate comment here Donate WeChat Pay