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 at 
http://groups.google.com/group/google-guice?hl=en.

Reply via email to