Hi,

while working on our headless implementation of the RESTy part of
Opensocial, it took me quite some time to find all the @Named
annotations that I have to supply information for. I was wondering if
we could benefit from replacing all the
@Named("shindig.something.or.other") with constants. @ $WORKPLACE we
use something like this:


public abstract class NamedConstants
{
    private NamedConstants() {
    }

    public static final String REQUIRED_CONSTANT_NAME = "required.constant";
    public static final Named REQUIRED_CONSTANT_NAMED =
Names.named(REQUIRED_CONSTANT_NAME);

}

and in the code you would use

     
bind(Foo.class).annotatedWith(NamedConstants.REQUIRED_CONSTANT_NAMED).to(FooImpl.class);

and

     public Baz(@Named(NamedConstants.REQUIRED.CONSTANT.NAME) Foo foo) { ... }

The advantage is that it is possible to figure out which constants are
in use in the code base, and (by adding meaningful comments to the
class above :-) ) figure out what they do. Also, the compiler will
catch possible typos in @Named and annotatedWith usage.

The process of putting this in is pretty much mechanical but some
work. I can do that if no one objects strongly.

-h

Reply via email to