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 Getting the Whole Forecast

Anas Fahad
Anas Fahad
16,079 Points

How are the classes related to each other in Forecast application?

I found it confusing by having Hour, Day, Current and Forecast work. does it follow a specific design pattern ? Do Hour and Day classes depend on Forecast class ?

1 Answer

Hi Anas,

The three main classes, Current, Hour and Day are pretty much the same classes. They hold slightly different information, by design, but they're not massively different. Thinking about it, I'm sure it would be possible to have just one class for these three and just use instances that are named appropriately. I'm happy to be wrong about that, but there's no inheritance occurring and they all hold broadly the same data, just sourced from different parts of the JSON.

The Forecast class is used as a wrapper to hold the multiple instances needed of the Day and Hour classes to populate the screen with these sets of data. The advantage of having the different classes may lie here. You can define the multiple instances inside this class but if they were just instances of a single class, that would be difficult, perhaps impossible. It is certainly clearer to read with the three detail classes.

So, Forecast sets out how the Current, Hour and Day are used as well as holds some common methods such as getIconId().

I hope that helps.

Steve.