Thanks for the fast response. The static instances are currently used for comparison and default value assignment. Since we do have pertty many such instances in different classes I think creating an Annotation for every Instance is just not maintainable. Also the comparisons to check if a on Object equals SWITZERLAND or GERMANY would be cumbersome if I had to get these Objects from Guice.
The getTranslation method is used to get a string representation for the internalCountryCode. That String must be fetched from an external Service. I guess it is possible to encapsulate the Translation of a Country within an other Service but it would be great if I could get it working within the Country Instances. On 29 Apr., 12:20, Miroslav Genov <[email protected]> wrote: > I don't know the whole idea of getTranslation() method, but here are > some code snippets that could give you idea how code could be re-organized. > > public interface DictionaryService { > > String getCountryTranslation(String countryName); > > } > > public class EuropeanDictionaryService implements DictionaryService { > private final Set<Country> europeList; > > public EuropeatDictionaryService(@Europe Set<Country> list) { > this.europeList = Collections.unmodifiableSet(list); > } > > public String getCountryTranslation(String countryName) { > for (Country country : europeList) { > if (country.getName().equalsIgnoreCase(countryName)) { > //do some stuff > } > } > return ""; > } > > } > > public class Client { > > public Client(@Europe DictionaryService europeDictionary, @Africa > DictionaryService africaDictionary) { > ........................... > } > > } > > Guice's Multibindings functionality could be used for country > grouping.http://code.google.com/p/google-guice/wiki/Multibindings > > Hope that this will help you find out how to remove static instances > from your code. > > Regards, > Miroslav > > On 04/29/2010 09:05 AM, senny wrote: > > > > > Hi, > > > We are currently integrating Guice into an existing Project. Most of > > the Objects are created via the Guice Injector and work fine but there > > is a case where I dont know the right way to Refactor it. We have the > > following Situation: > > > public class Country { > > public static final Country SWITZERLAND = new Country(123); > > public static final Country GERMANY = new Country(456); > > > private Integer _internalCountryCode; > > > public Country(Integer internalCountryCode) { > > _internalCountryCode = internalCountryCode; > > } > > > public String getTranslation() { > > //I need a Service from Guice to perform the translation > > } > > > } > > > The problem is that of course the static Country instances do not get > > created by Guice and so I cant inject the necessary service to > > translate into the objects. Is there a way to refactor that code to > > make it more guicey? > > > Cheers, > > -- Yves > > -- > 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 > athttp://groups.google.com/group/google-guice?hl=en. -- 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.
