About OOP and the MVC pattern…

Discussion in 'Mac Programming' started by CMT, Apr 1, 2010.

  1. CMT macrumors member

    CMT

    Joined:
    Aug 24, 2009
    #1
    I think I'm experiencing some really crazy thoughts about OOP, as I'm pretty new to it. Well, lets see if someone can help me organize the ideas.

    Let's say we are going to build a simple app. One window, a slider and a label. Putting this inside MVC [obviously this is just a simple example I'd never do MVC for this app :) ]

    In the model, we would have a class with one variable, to store a value and also a @property to access that var.

    In the view, the .xib containing the slider and label (I believe these objects fit in the view)

    In the controller, I have to instantiate the slider and label again and also a model object plus other methods telling when the view changes and updating it.

    Now, my question. I need to create a model object that remains live. So I can set its value and also retrieve it to show in the label. if i'm correct, I can do this by retaining the object, but where to create and retain it?

    Inside a method in a class? if so, which one?

    Well I'm quite lost with concepts as you can see. If needed I can do a more detailed description.

    Thanks in advance!
     
  2. jared_kipe macrumors 68030

    jared_kipe

    Joined:
    Dec 8, 2003
    Location:
    Seattle
    #2
    Usually in either the appDelegate or the controller.

    For example, the controller would have an ivar of the same type as the model. And then in the method - viewDidLoad you would alloc/init that model object and set it as your ivar, then setup the position of the slider from the model objects value OR set the model's value and the slider to some predetermined value.
     

Share This Page