Karthik Krishnan
unread,Aug 1, 2008, 3:29:28 AM8/1/08Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to google-guice
I have an Strategy implementation
public interface ContactRecipientStrategy {
void deliverToRecipient(Recipient recipient) throws Exception
}
Two implementations
public class EmailRecipientStrategy implements
ContactRecipientStrategy {
}
public class TelephoneRecipientStrategy implements
ContactRecipientStategy {
}
In my factory implementation, I have a switch condition which returns
.....
public ContactRecipientStategy getStrategy(String emailAddress) {
bool flag = ifValid(emailAddress);
if (flag) {
return new EmailRecipientStrategy();
}
return new TelephoneRecipientStrategy();
}
Is there a way to implement this? I have to call this factory method
from another method body.
To bind my implementation, I did the following
bind(ContactRecipientStrategy).annotatedWith(FlagTrue.class).to(EmailRecipientStrategy.class);
bind(ContactRecipientStrategy).annotatedWith(FlagFalse.class).to(TelephoneRecipientStrategy.class);
I don't want to create two annotation classes for a switch condition.
Is there a better way? I tried AssistedInject, but I can not use it as
it is not Mavenized in Guice 1.0 unless I reinstall it everytime I
build. Please help me here.
Thanks,
Krishnan