Получить класс с помощью фабрики

Всем привет. Мне нужно в одном из методов класса получить экземпляр другого класса в зависимости от значения переменной.Сделал так.

Интерфейс

public interface Geography {
 void geo();
}

class GeographyFactory

public class GeographyFactory{
 private static Context mCtx;
 public GeographyFactory(Context ctx) {
  mCtx = ctx;
 }


 public <GTypes> Geography getGeography(GTypes type){
         Geography toReturn = null;
  if (COUNTRY.equals(type)) {
   toReturn = new CountryRequest(mCtx);
  }

         return toReturn;
 }

 }

class CountryRequest

public class CountryRequest implements Geography {

 private static Context mCtx;
 public CountryRequest(Context ctx) {
  mCtx =ctx;
 }

 @Override
 public void geo() {
  ApiCallCountry apiCallCountry = new ApiCallCountry(mCtx);
 }
}

class SearchGeo

public class SearchGeo{
 public SearchGeo(Context ctx,String where, View aut, TextView selectedText){
..
}
private void makeApiCall(Context ctx, String text, String where) {

GeographyFactory geographyFactory = new GeographyFactory(ctx);

}
}

Как мне в makeApiCall() получить экземпляр new ApiCallCountry(mCtx) используя фабрику?


Ответы (0 шт):