Cocoa 模型应该包含自己的数据访问方法吗?

发布于 2024-11-09 09:09:00 字数 412 浏览 0 评论 0原文

我对在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夜未央樱花落 2024-11-16 09:09:01

我也有 .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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文