企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
~~~ public interface IUserDao { void save(); } ~~~ ~~~ public class UserDaoImpl implements IUserDao { @Override public void save() { System.out.println("保存数据"); } } ~~~ ~~~ public class UserDaoProxy implements IUserDao { private IUserDao userDao; public UserDaoProxy(IUserDao userDao) { this.userDao = userDao; } @Override public void save() { System.out.println("userDao before"); userDao.save(); System.out.println("userDao After"); } } ~~~ ~~~ IUserDao userDao = new UserDaoImpl(); UserDaoProxy proxy = new UserDaoProxy(userDao); proxy.save(); ~~~ ### 优缺点 ``` ```