Is it a good practice to annotate two different classes with same annotation?

42 views
Skip to first unread message

Bingkun Guo

unread,
Jan 22, 2016, 6:55:23 PM1/22/16
to google-guice
For example, bind both class A and class B to annotation @XXX.

Nate Bauernfeind

unread,
Jan 25, 2016, 8:14:18 AM1/25/16
to google-guice
It's certainly not bad practice. Though, the context depends on your situation entirely.


It's certainly conceivable that in addition to an @Left Leg and a @Right Leg you might want an @Left Arm and an @Right Arm.

Depending on your situation there might be other tools that are worth using instead; tools such as child injectors, private injectors, or multi-binders solve similar problems. For example, child injectors are great if you build an object graph for each annotation (or in this context theoretically a 'namespace'). And so on. Pick the one that appears to have the least manual/human overhead and go with that. You can always try another approach if you don't like the direction your current one is going.

On Fri, Jan 22, 2016 at 6:55 PM Bingkun Guo <taff...@gmail.com> wrote:
For example, bind both class A and class B to annotation @XXX.

--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-guice...@googlegroups.com.
To post to this group, send email to google...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/160dc72e-4b78-4ed6-86eb-4826479d3a6c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages