I know that I am for responsible for this in the code, but in a object-oriented and MVC sense, who should really load the model. I have a model for representing RSS feeds that is being loaded from a url. The model is really thin and the controller manages downloading and parsing of the XML and then passes it on to the model. Is it better to do it that way or let the model be responsible for initializing itself?
The code in the controller that manages retrieving feeds looks something like this:
// EntriesController.m
- (void)getFeedsFromWeb {
Parser *parser = [[Parser alloc] init];
[parser addListener:self];
Downloader *downloader = [[Downloader alloc] initWithParser:parser];
[downloader getFeed:@"http://www.example.com/rss"];
[parser release];
}
- (void)notify:(Feed *)aFeed {
self.feed = aFeed;
[self updateView];
}
The Downloader begins downloading and accumulating the response data, and passes it on to the Parser. When the Parser is done, it calls a callback method notify:(Feed *)feed
in the EntriesController class, which updates it's model.
I don't think I am really decoupling the responsibilities in the Controller here, so I'm thinking of putting all this responsibility in the model itself. Add methods like
// Feed.h
- (void)initWithContentsOfURL:(NSURL *)feedURL
- (void)initWithContentsOfDatabase:(sqlite *)database
which does all the work in the model class itself. Is this a good approach and should the model be responsible for fetching data from various data sources?