Doesn't Quiz violate the Model-View-Controller Paradignm


#1

I’m working through chapter 1. Sorry I can’t say what page because there are no page numbers on Kindle version.

I note that the apps ‘View’ variables, objects and methods are programmatically controlled with/contained within the QuizViewController.xib. Makes sense.

I also note that the ‘Contoller’ methods and variables (eg: IBActions showQuestion and showAnswer’ and NSSstrings *question and *answer )are contained within the QuizViewControler.m file. Also makes sense.

If we were staying true to the Model-View-Controller paradigm where never the three shall meet programatically, shouldn’t the apps ‘Model’ details/objects/methods/varialbes be contained in a third file. The question/answer array is part of the apps model right (see Figure 1.12). Shouldn’t they be declared, instantiated another file/object/method rather than witin the initWithNibName function contained in the SAME QuizViewController.m file?

Just say’n? Or am I missing something here? :slight_smile:

…Dale


#2

Hi,

I think you’re right. I was searching for exactly the same topic if this was already asked here as I was asking myself the same…
Maybe it was done to simplify the exampel but I think it would be better to have the separate file for the model to be compliant with to Figure 1.12.

Regards
splinetime


#3

This question has been asked before, so it’s arguably confusing to some folks, especially if they come from a different platform.

The important concept to understand here is that the controller does NOT contain the views and strings. Instead, it has pointers to these objects. It wouldn’t be MVC if, say, the controller drew the screen and held the string memory in its own data. It is MVC because the controller, views and strings all exist independently - its just that the controller knows where these objects live in memory.


#4

Hi Joe,

So are you saying that we don’t / or shouldn’t create a new file to hold the model data and just implement the code within the AppViewControler.m file?


#5

Well, I’m not sure what creating a new file would do here?

Are you saying you want to create a new class to hold the model data?

If so, why?

There is already an NSString class in an NSString.m file. You are using that class to represent the model objects.

Is the issue that the model objects are being created in the controller? They gotta be created somewhere.


#6

Well, I just think it would make it easier to have all three elements separate. However, putting the model data in the controller does seem like an efficent way of doing things.

I’m still new to all this, I was just wondering.


#7

Well, think of it this way: you aren’t putting the model data in the controller. The model data is in two NSArrays and six NSStrings.

The controller, however, has a reference to this model data. Without the reference, it would be unable to locate the model data.

I think the important piece of the puzzle here to understand here is that objects don’t “contain” other objects. Objects have pointers so that they know where to find other objects.


#8

Thanks for the explanation, Joe.

I’m re-reading the whole book from scratch. I rushed it last time round and realised half way through I was missing the point.