Cocoa 模型应该包含自己的数据访问方法吗?
我对在 Mac 上开发 Cocoa 应用程序还比较陌生,并且有 .NET C# 背景。我想知道 Cocoa 模型对象是否应该包含自己的数据访问方法,例如创建、更新和删除等。Apple 文档似乎倾向于模型做所有事情,但拥有一个模型(即 UserModel)似乎并不正确有一个名为 GetUsers 的方法,它返回 UserModel 的集合!
在 ASP.NET MVC 中,我的所有模型都只是业务对象(即用户)或视图的表示。使用上面的示例,控制器有责任调用服务(业务层或类似性质的东西)并获取 UserModel 对象的列表。同一控制器还会用数据填充 UserModel 并将其作为参数传递给其他服务,然后该服务可以执行更新或删除。
关于这个主题的任何想法都将不胜感激,因为 Apple 的示例代码往往相当简单,并且没有真正涉及 CRUD 类型操作。
提前致谢。
I am relatively new to developing Cocoa applications on the Mac and come from a .NET C# background. I was wondering if a Cocoa Model object should contain its own data access methods such as Create, Update and Delete etc. Apples documentation seems to lean towards the Model doing everything but it doesn't seem right to have a Model (ie UserModel) which has a method named GetUsers which returns a collection of UserModels!
In ASP.NET MVC all my Models are just a representation of a Business object (ie a User) or a View. Using the example from above it would be the controllers responsibility to call a service (Business Layer or something of that nature) and get back a list of UserModel objects. The same controller would also populate a UserModel with data and pass that as a parameter to some other service which could then perform an Update or a Delete.
Any thoughts on this subject would be greatly appreciated as example code from Apple tend to be rather simple and don't really touch on CRUD type operations.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我也有 .NET 背景,我同意 Apple 有时会混淆一些事情。我倾向于保持域模型干净并实现数据访问服务。我唯一不同的做法是,如果我使用 CoreData,其中我的域级对象也是 CoreData 对象(因此它们具有底层数据持久性),但是我仍然使用存储服务/数据访问服务来检索和保存。
如果您想要我使用的存储服务/DAL 的示例,那么我的一篇博客文章包含它....CoreData 示例
I also come from a .NET background and I agree that Apple sometimes confuse things a bit. I tend to keep my domain models clean and implement a data access service. The only time I do it differently is if I am using CoreData in which my domain level objects are also CoreData objects (so they have underlying data persistence) HOWEVER I still use a Storage Service / Data Access Service to retrieve and save through.
If you want an example of a Storage Service / DAL I use then one of my blog posts contains it....CoreData Example