耦合 解耦

//存在编码器依赖 耦合中的体现
//只要看见new,那么就会存在编译器依赖,耦合重的体现 
//解耦思路: 去掉new关键字
DriverManager.registerDriver(new com.mysql.jdbc.Driver());
//编译器不依赖,运行期才依赖
Class.forname("com.mysql.jdbc.Driver");
//问题: 虽然解决了编译期依赖,但是存在硬编码问题, 可以通过配置文件解决

//解耦思路: 配置文件+反射
//自定义IOC的时候,就是这种思路,来进行解耦

猜你喜欢

转载自blog.csdn.net/kimyundung/article/details/113616649