Thanks for your question, @ilandbt ! :]
ViewController
receives the businesses
from its client
, which is an instance of YLPClient
and is used to get search results from Yelp.
Each BusinessViewModel
knows about only one YLPBusiness
. The purpose of BusinessViewModel
(like all view models) is transforming model information into values that can be displayed on a view. Hence, one BusinessViewModel
transforms one YLPBusiness
into values that can be displayed. It’s not required (and doesn’t make sense) for BusinessViewModel
to know about all YLPBusiness
objects, as it only deals with just one.
However, you’re right that technically the ViewController
doesn’t need to hold onto businesses
! Rather, it could have immediately converted the businesses
into businessViewModels
after it receives them from Yelp.
This makes sense for this chapter here, but in a later chapter, you’ll add a Filter
to only show certain businesses, based on their star
rating.
This Filter
uses businesses directly, instead of the view models.
Taking another look at the code, however, this too could have used view models instead of the models directly!
I’ll talk with @jstrawn about updating these chapters to have the view controller hold onto the view models only, instead of the models, in the next iteration of this book. :]