iPhone 开发环境中的 MVC
到目前为止,我已经阅读了一些有关 iPhone 应用程序开发的 MVC 设计模式的资源。然而,我有一个与 iPhone 开发环境中的 MVC 模型部分相关的问题。
首先,我想说一下我对 MVC 的看法,
模型: 与我们拥有的有关应用程序对象的数据相关。示例:火车模拟器的应用,模拟中的每列火车都将拥有自己的属性,并将保存在火车模型中。
控制器:是控制UI更新的东西。它保留对列车模型的引用并检查模型中的任何更改,如果有则更改该特定列车的视图。它会不断检查任何 UI 输入,以便可以更改模型内的数据。
视图:这是相当明显的视图是关于UIView的,我们在屏幕上看到的。
现在,问题是...
模型是否必须持久才能被视为模型?或者我可以 有一个类,它的变量没有任何持久性。那会吗 也被视为模型,或者模型必须存储在类似的地方 在 CoreData 或 .Txt 文件等中...
感谢您的任何输入!
I have read several resources so far about MVC design pattern for iPhone application development. However I have one question related Model part of MVC in iPhone development context.
Firstly, I would like to say what I think of MVC,
Model : is related to a data which we have regarding our application's objects. Example : Application of a Train simulator than, Each train on simulation will be having it'e own attributes and that will be saved inside Train model.
Controller : is something which controls UI updates. It keeps a reference to Train model and checks for any changes in model, If there is than change the View of that particular train. And it keeps checking for any UI input so it can change data inside Model.
View : This is fairly obvious View is all about UIView, What we see on screen.
Now, Question is...
Does Model has to be persistent to be considered as a Model? or I can
have a Class which has variables without any persistency. Would that
be considered as Model as well, Or Model must be stored somewhere like
in CoreData or .Txt file etc....
Thanks for any input!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不,MVC 背后的想法实际上与数据库无关,尽管这很常见。该模型应该简单地捕获所有业务逻辑。如果您正在构建一个计算器,视图是显示屏和按钮,模型是知道如何加和减的代码部分,控制器是连接两者的部分。不涉及坚持。
No, the idea behind MVC does not actually relate to databases, although that is usual. The model simply should capture all the business logic. If you are building a calculator, view is the display and the buttons, model is the part of code that knows how to add and subtract, and controller is the one that connects the two. No persistence involved.
不,模型不必是持久的。
理论上,为了简单起见,启动项目的一个好方法是使用非持久模型。然后,当您更改模型以使其持久化时,您不必对视图或控制器进行任何更改,因为您将设计界面以不了解模型的详细信息。
实际上,如果您打算在模型持久化时使用 Core Data,那么这在 iPhone 上并不是一个好主意。 Core Data 要求您以稍微不同的方式设计您的类。尽管在更改模型时不必对视图和控制器代码进行大量更改,但您仍必须对模型进行大量代码更改。如果您知道您将使用 Core Data,最好立即开始使用。
No, a model doesn't have to be persistent.
In theory a good way to start your project would be to use a non-persistent model for simplicity. Then when you change your model to become persistent, you should not have to make any changes to your view or controller, since you will design the interface to be unaware of the details of the model.
In practice that's not a great idea on iPhone if you're planning to use Core Data for your model when you make it persistent. Core Data requires you to design your classes in a little bit of a different way. Even though you shouldn't have to make many changes to your view and controller code when you change your model, you will have to make a lot of code changes to your model. If you know you will be using Core Data, better to start right off with it.
只要您的控制器可以支持,它就可能会有所不同或改变。
根本不是。
如果适用,您可以使用任何模型。模型只是实际逻辑/数据库/网络访问/blablabla 的另一个抽象...
It may vary or transform as long as your controller can support it.
Not at all.
You can use any Model if applicable. Model is just another abstraction of your actual logic/database/network access/blablabla...