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!
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
Nathan Kinsey12,283 Points
How are we following the MVC pattern?
We put the MainActivity in the "ui" package which makes sense (sorta) because that is the class that manipulates all of the view code. However, the MainActivity class also gets the JSON data from the web API. Shouldn't JSON weather data be a part of the model package so that the UI doesn't directly interact with raw data? Are we violating the MVC pattern, or am I just confused as to how it is supposed to work?
Jacob Biros2,241 Points
I am not super knowledgeable on this, so I can't 100% say this, but from what I have been reading, there are various ways to compartmentalize your package. One might be to separate them into Model, View and Component classes, while another may be to separate them into packages containing similar functions. I am sure there are other organization patterns. In this case it looks like they are being separated based on function.
Also you are correct about separating the API call and the user interface, although I don't think it needs to be separate classes, just separate threads. In this case, we let OkHttp do the work so when its activated it creates a separate thread that prevents it from clogging up the user interface thread and making the user feel that the app is slow. I think in this case you can consider the weather data itself obtained through the API to be the model, the view to be what the user is seeing and the controller to be the classes that control where and how the data is displayed.
Sorry if my explanation is confusing. I'm still working to internalize it all myself.
Steven Stanton59,998 Points
I think the Activity class is the "Controller" part of the MVC model. It talks to the View (including the xml files) and to the Model, but the Model doesn't speak to the View directly. The packages don't necessarily represent the MVC structure, but the way the code operates does follow MVC.