2008/10/15 Bob Lee <[EMAIL PROTECTED]>: > On Tue, Oct 14, 2008 at 5:25 PM, Gili Tzabari <[EMAIL PROTECTED]> > wrote: >> >> I believe this ties into Joshua Bloch's "good APIs have good >> defaults" paradigm (I remember him saying this at some point). In other >> words, don't make the user do anything that you can reasonably do for >> him automatically. I don't know whether it applies in this context but I >> suspect it does. I don't think there is any danger that the lack of >> @Inject will somehow reduce the readability of the code. It is pretty >> clear that if there is only one constructor and Guice somehow constructs >> an instance of that class than it must obviously be using that >> constructor. > > Ah, but when you're looking for callers in a non-Guice-aware IDE (or just > plain reading the code), the @Inject makes it obvious that this class is > injected by Guice.
Not really - it indicates it *may* be injected by Guice but until you've looked at uses of the Class you don't know how its being bound. e.g. someone may be invoking the constructor directly in a provider method or binding an instance directly. If a class has only one constructor and its public and it has arguments - you *know* its being invoked - from anywhere (guice or regular java code) - whether it had an @Inject or not - so this seems a silly argument to me :) So there's definitely plusses and minuses to this. Sure adding a new constructor breaks things - but then it would break things very fast (in the same way that adding a parameter to a constructor might break things too). Folks should run unit test cases so catch these breakages pretty quickly. On the plus side - think of the zillions of Java classes out there that Guice would be able to automatically inject without folks having to write their own magic AOP bytecode swizzler, get access to the code, hack it and re-release it or write custom providers. -- James ------- http://macstrac.blogspot.com/ Open Source Integration http://fusesource.com/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "google-guice" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/google-guice?hl=en -~----------~----~----~----~------~----~------~--~---
