《第3章 IoC容器概述》学习笔记01
程序员文章站
2024-01-19 09:08:52
...
Case 01:通过演员安排剧本
1,演员类
2,剧本类
3,测试类:
4,运行结果:
1,演员类
package com.baobaotao.ioc.ioc01; public class LiuDeHua { public void responseAsk(String saying) { System.out.println(saying); } }
2,剧本类
package com.baobaotao.ioc.ioc01; public class MoAttack { public void cityGateAsk() { // 1, 演员直接侵入剧本 LiuDeHua liuDeHua = new LiuDeHua(); liuDeHua.responseAsk("墨者革离"); } }
3,测试类:
package com.baobaotao.ioc.ioc01; public class Test { public static void main(String[] args) { MoAttack moAttack = new MoAttack(); moAttack.cityGateAsk(); } }
4,运行结果:
墨者革离