In MVC where do you put references to your model Classes?

前端 未结 5 1682
野的像风
野的像风 2021-02-04 06:33

I have been wondering for a while, after asking different people and without any of them providing what I would call an \"at least a bit concrete answer\":

Quest

5条回答
  •  南笙
    南笙 (楼主)
    2021-02-04 07:19

    It is tempting to put everything in the AppDelegate, but if you start doing this, then your AppDelegate will be full of reference hacks. If you are doing a strict MVC, then you should have 3 things:

    • A Model
    • A View Controller (Only for view logic)
    • A Controller (For coordinating between the view and the model)

    So for example, I have a model Foo and a Foo controller. I would have:

    • Foo.m (Model)
    • FooViewController.m (Displays a Foo)
    • FooController.m (Controls the logic)

    And finally, to answer your question, I would store my references to Foo's in the foo Controller. I like to use singletons for my controllers, but thats just me. If you do use a singleton, you can just do something like this: [[FooController sharedInstance] listOfFoos] to get your Foo's

提交回复
热议问题