CS193P Assignment 3, Hint#5 - What is the model?
Asked Answered
F

6

6

I am working my way through the Stanford Fall 2011 iOS course: http://www.stanford.edu/class/cs193p/cgi-bin/drupal/

I am onto assignment#3: http://www.stanford.edu/class/cs193p/cgi-bin/drupal/system/files/assignments/Assignment%203_2.pdf

As a summary, prior assignments have asked to build a regular calculator and now this assignment is asking us to push this calculator unto a Nav controller and create a segue from that CalculatorViewController to a GraphViewController that would plot the function stored in the "CalculatorBrain". This CalculatorBrain was the model for the original CalculatorViewController.

Hint#5 keeps on talking about the fact that now the model for the GraphViewController is different than the model of the CalculatorViewController and I can't figure out what he means by that.

The only way I have been able to build the new MVC is by creating a protocol in the GraphView (view) of the GraphViewController with an object called "dataSource" of type ID. And then in the GraphViewController: adopting that protocol, instantiating the GraphView and setting itself as the datasource:

-(void) setGraphView:(GraphView *)graphView
  {
  _graphView=graphView;   
  self.graphView.dataSource=self;
  }

And then in the original CalculatoViewController, using the prepareForSegue to pass the program to the GraphViewController:

-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
  if([segue.identifier isEqualToString:@"Graph"])
  {
    GraphViewController *myGraphViewController = segue.destinationViewController;
    myGraphViewController.myCalculator=self.myCalcBrain;
  }
}

So that seems to work fine. So if that works, that means that the GraphViewController's model is really the original Calculator Brain that he specifically said it is not!

I mean isn't the fact that, during the segue, I am assigning to the Graphviewcontroller calculator property the calculator model instance from the original CalculatorViewController and then using a protocol to return the Y value from the GraphViewController to the GraphView means that the model for the GraphViewController is really just the original CalculatorBrain model.

Fraise answered 22/4, 2012 at 11:47 Comment(2)
Isn't "What is the model for this new view controller?" exactly what you're being asked to figure out? What do you think it should be? What data does the graphing view controller operate on?Preengage
@Preengage Thanks. What was really confusing is that I defined a protocol (with a method and a property) in the GraphView class and then had the GraphViewController implement the protocol (and the method) to have that method reply with the Y value of the x being passed. This bothers me because in my mind, that tells me that the model values (of Y) for the GraphVC is still derived from the main "CalculatorBrain" class which he said it is not. Maybe this is just semantics....Am I overthinking this?Fraise
M
3

I do believe the model is the "program", an NSArray object. It can't be the description of the program cause there is no easy way to compute the "y" value given a NSString. You will have to re-parse the NSString into a stack (NSArray). As such, isn't it more direct to have the model as an NSArray/program?

Medardas answered 24/5, 2012 at 6:0 Comment(0)
S
1

I hate to answer this for you, since that's what you are supposed to do, but I do believe you are over thinking it, so here's what he wants you to realize/do:

Your model will be a new class that inherits from the model from the original calculator. That's why he says you will only need to create the view and controller from scratch. You will have to create a model class too, but a lot of the necessary code already exists in the old calc model, so you just inherit that and add the necessary additional functionality.

Hope that helps, and glad to see that you are using those courses. They are a great free tool!

Shame answered 27/4, 2012 at 16:45 Comment(1)
What kind of add'l functionality would you add to the inherited model. There is really nothing to add. The GraphView is iterating through x and asking from ... and getting back the Y value. And since the view and the model cannot talk to eachother, this tells me that you suggest setting up the GraphVC to instantiate a Calc Brain (from the inherited model) but then still get the original Calc object passed down through the top level MVC. It just seems to be overly complex compared to just that the model is just the formula as @Matt. I hope we can get some more feedback here. ThanksFraise
M
1

I struggled a little with this question too when I was doing that assignment. I came to the conclusion (rightly or wrongly) that the model is just a formula - which seems like the conclusion you've come to, which while not being the calculator brain class, is very closely related to it!

edit:

I've just gone back and looked at my calculator program (i'm currently on the flickr assignment, so haven't looked at it in a while)

Looking at the basic calculator, the model was a "calculatorbrain" object

in the hints of the assignment it says

Don’t get this Controller’s Model confused with your CalculatorViewController’s Model. THEY ARE DIFFERENT. And don’t over-think this. Your new Controller’s Model is near at hand!

the graphview controller's model I have is a program. As in the program as defined in the calculatorbrain - just a stack of operations (NSArray) rather than a calculatorbrain. I just passed the current program via the segue into the graphview controller.

To me it seems to fit the details of the hint - the program is close at hand when you segue to the graph, but it it's not the same as the model of the calculator.

The hint doesn't say that it's not related to the model though.

But I'm a bit of an iOS n00b too, so this is just my take!

Medicable answered 28/4, 2012 at 20:45 Comment(0)
D
1

The model should just be a NSString describing the "program" that you are going to graph. As in the program that Calculator Brain returns to you!

id program = [self.dataSource.brain program];
Demerol answered 29/4, 2012 at 8:12 Comment(1)
this might be overcomplicating it. You would then have to change the NSString back to an array to be able to graph it...Fraise
B
1

My Model was the "program" also!

Beefcake answered 17/5, 2012 at 20:18 Comment(0)
F
0

@Lee Cjin Pheow, you are correct. As I have progressed through this course, this has become more apparent. So the model is just an NSArray holding the program. I think my confusion was because of a n00b assumption I made that the Model in an MVC has to be its own class/file and hence my search for a Model class/file. As I am progressing, I am seeing the professor have an MVC where the Model is really just a property for example that is sitting in the Controller. I just have to maintain the Yellow do not cross lines in my simple mind.

Fraise answered 3/6, 2012 at 23:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.