第一课 spring的一点理论 2006-04-05

1.         
  优点 .
.with a couple of lines of configuration instead of embedded code
.Spring is much simpler than traditional J2EE alternatives. With Spring, you code your applications as plain old Java objects (POJOs)
2.
做法 :
1.   A client uses another class that we'll call a service. The client has a property that accepts a service. The service is wrapped in an interface. The client can't see the implementation of the service. But this code is not yet loosely coupled: you still have to create the service somewhere. With dependency injection, a third-party, called the assembler or container, creates both the client and service, and then sets the value of aService (which is a reference to an instance of Service) to satisfy the dependency.
2.       Wrap the service in an interface(ArrayListRentABike implements RentABike  后者就是接口 )
3.       Add a property to the client, to refer to the service.(class CommandLineView 里面包含 RentABike 对象 )
4.       With a third party framework or custom code, build the service and populate the property.(RentABikeAssembler, 里面的 main 方法里面完成 ,creates both the client and service, and then sets the value of aService ):                                                                                                                                                                 CommandLineView clv = new CommandLineView( );
        RentABike rentaBike = new ArrayListRentABike("Bruce's Bikes");
        clv.setRentaBike(rentaBike);
 
3.the ideas behind the movement are simple. Program using interfaces, and let a third party inject the dependency instead of setting it yourself.You're going to eventually replace the assembler with Spring....
Of course, dependency injection is not the only way to manage dependencies. In fact, it's not the only good way. J2EE users tend to use service locators
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值