title: android MVP - How should the network layer be called , from model?
body: <p>In MVP android i believe the network layer (retrofit , volley etc) should NOT be apart of the model. But I need a firm example on how to construct the model then. Should the model be a singleton that the network layer simply creates when api call completes ?  </p>
  
  <p>Lets take a look at a presenter i have for my one of my activities:</p>
  
  <pre><code>    public class MainActivityPresenter implements IMainPresenterContract, Callback {
  
      IMainActivityViewContract view;//todo set up a weak reference to View to avoid leakage
      NewsService interactor;
  
      public MainActivityPresenter(IMainActivityViewContract view, NewsService interactor) {
          this.view = view;
          this.interactor = interactor;
      }
  
  
      public void loadResource() {
          interactor.loadResource();
      }
  
  
      public void onRequestComplete(final NewsEntities newsEntities) {
  
          view.dataSetUpdated(newsEntities.getResults());
      }
  
      @Override
      public void onResult(final NewsEntities newsEntities) {
          onRequestComplete(newsEntities);
      }
  
      public void goToDetailsActivity(Result result) {
          view.goToDetailsActivity(result);
      }
  }
  </code></pre>
  
  <p>So my question is about the NewsService interactor parameter i am passing into the constructor.  I was assuming this should be model data and not a networking service. But what should it look like then ?   Currently mine looks like this:</p>
  
  <pre><code>    public class NewsService implements INewsServiceContract {
  
      private Gson gson;
      private Callback mCallback;
  
  
      public NewsService() {
          configureGson();
      }
  
      private static String readStream(InputStream in) {
          StringBuilder sb = new StringBuilder();
          try (BufferedReader reader = new BufferedReader(new InputStreamReader(in))) {
  
              String nextLine;
              while ((nextLine = reader.readLine()) != null) {
                  sb.append(nextLine);
              }
          } catch (IOException e) {
              e.printStackTrace();
          }
          return sb.toString();
      }
  
      public void setCallBack(Callback cb) {
          mCallback = cb; // or we can set up event bus
      }
  
      private void configureGson() {
  
  
          GsonBuilder builder = new GsonBuilder();
          builder.excludeFieldsWithoutExposeAnnotation();
          gson = builder.create();
      }
  
      @Override
      public void loadResource() {
  //Todo could use a loader instead help with the config change or a headless fragment
          new AsyncTask&lt;String, String, String&gt;() {
              @Override
              protected String doInBackground(String... params) {
                  String readStream = "";
                  HttpURLConnection con = null;
                  try {
                      URL url = new URL("https://api.myjson.com/bins/nl6jh");
                      con = (HttpURLConnection) url.openConnection();
                      readStream = readStream(con.getInputStream());
                  } catch (Exception e) {
                      e.printStackTrace();
                  }
  
                  finally {
                      if(con!=null)
                      con.disconnect();
                  }
                  return readStream;
              }
  
              @Override
              protected void onPostExecute(String result) {
                  super.onPostExecute(result);
                  NewsService.this.onRequestComplete(result);
  
  
              }
          }.execute();
      }
  
      private void onRequestComplete(String data) {
  
          data = data.replaceAll("\"multimedia\":\"\"", "\"multimedia\":[]");
          news.hotels.com.sample.Model.NewsEntities newsEntities = gson.fromJson(data, NewsEntities.class);
          mCallback.onResult(newsEntities);
      }
  }
  </code></pre>
  
  <p>so as you can see the NewsService in this case is doing the network calls. I think i should not have passed this into the presenter. But how can the model be constructed then ? who calls the NewsService ?</p>
  
  <p>UPDATE: THIS QUESTION WAS a long time ago, everyone please use clean architecture approach, and let your presenter know nothing about the network layer. </p>