On Apr 7, 2012, at 8:07 PM, Henrique Prange wrote:
> Suppose you have a Service interface and a BasicService implementation for
> it. This Service is required across your components. So you have something
> like this:
>
> class ComponentOne {
> Service service = new BasicService();
> }
>
> class ComponentTwo {
> Service service = new BasicService();
> }
>
> ...
>
> Then, the project evolves, and you develop a new AdvancedService
> implementation for the Service interface. You have to traverse the entire
> code base updating the instantiation of Service.
>
> On the other hand, if you use Guice, you can delegate the creation of
> Services to Guice, and inject the instances of Service when required. You
> write code like this:
>
> class ComponentOne {
> @Inject
> Service service;
> }
>
> class ComponentTwo {
> @Inject
> Service service;
> }
>
> ...
>
> And you configure a Guice Module to specify that you want an instance of
> BasicService (or an AdvancedService) when you need a Service.
>
> class AppModule extends AbstractModule {
> void configure() {
> bind(Service.class).to(BasicService.class);
> }
> }
>
> If you need to change the implementation class, you just have to redefine
> your module:
>
> class AppModule extends AbstractModule {
> void configure() {
> bind(Service.class).to(AdvancedService.class);
> }
> }
>
What if I want an advanced service on component one and a basic service on
component two?
Ramsey
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list ([email protected])
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com
This email sent to [email protected]