Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Android Lists and Adapters (2015) Updating the Data Model Adding a New Data Model Object

Benjamin McKenzie
Benjamin McKenzie
7,455 Points

MVC

Ben mentioned that the project is following the MVC pattern, I understand how CurrentWeather and Hourly would both be models, and MainActivity is a controller, but all of the Okhttp code for getting json is in the MainActivity class. Shouldn't this be in a model class?

1 Answer

Seth Kroger
Seth Kroger
56,413 Points

No, that sort of code shouldn't go into the model class. It is more like a controller. Much like the Activity bind the values in the view to the values of the model, it binds the values retrieved from the API to the model. The API can be considered a different View of data with with the controller acting as the intermediary between the Model and the two different Views. It is possible to separate out the OkHttp code into a new class that handles the API, leaving the Activity with only the UI to be concerned about. But it wouldn't be added to the model, it would be a separate controller.