xiaodududu / google-guice

Automatically exported from code.google.com/p/google-guice
Apache License 2.0
0 stars 0 forks source link

Removing the finalization of the AbstractModule.configure(Binder) #593

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I would like to submit a small issue related to extending the Guice framework.

As the author of a small extension for the Guice I came to the point when I had 
to create my own Module implementation. This module is an entry point to my 
extension, so my users have to extend it and implement a single abstract 
method. As far as I know that is "the usual" way and multiple extensions also 
do it like this.

The problem is that my module has to register additional bindings in the Binder 
_after_ all module configuration is done. The simplest way to achieve this is 
to follow a pattern already used in the ServletModule. The configure() 
implementation firstly calls abstract configureServlets() and then performs any 
additional operations. In my opinion however this solution has a main drawback 
-introduction of yet another "configureBis" method makes it more difficult for 
the users to use the extension. Of course someone may say that good 
documentation should suffice. Opinions vary, but from my viewpoint it is better 
not to modify the contract if not strictly necessary.

An alternative solution not having such a disadvantage is to create a module 
from scratch, without reusing existing implementations. Since the Module itself 
is an interface it is possible, but to keep the DSL not-modified it would 
require to copy almost all functionality from AbstractModule.

Above solutions do not require any changes in the Guice source code. The 
globally best solution however does.

Removing the finalization of the AbstractModule.configure(Binder) method would 
greatly ease the development of similar extensions. Such a change does not 
break backward compatibility and has a rather small impact on the existing code 
base.

On the other side keeping the method final in a longer perspective will lead to 
multiple extensions not reusing AbstractModule. Such a trend may result in the 
incompatibilities of the internal DSL among extensions.

What do you think about such a modification?

Original issue reported on code.google.com by Aleksand...@gmail.com on 23 Jan 2011 at 2:02

GoogleCodeExporter commented 9 years ago
ServletModule should have made configureServlets() abstract, so that subclasses 
would know what to implement.

Removing the final on configure(Binder) would make it so that subclasses need 
to remember to call super.configure(binder) if overriding and would make it 
easier for users to break things accidentally and in unexpected ways.

Classes shouldn't be reused just to make it easier (where easier means less 
typing).

Original comment by sberlin on 24 Jan 2011 at 6:13