简体   繁体   English

在 Mac OS X 应用程序中具有 DAL 和 BLL 层是否可行?

[英]Is it feasable to have DAL and BLL layers in a Mac OS X Application?

I am developing a Mac OS X application using Objective-C and Xcode 4 and want to find out the best way of handling data access and undertaking business logic tasks without having to use CoreData.我正在使用 Objective-C 和 Xcode 4 开发 Mac OS X 应用程序,并且想找出处理数据访问和执行业务逻辑任务的最佳方法,而无需使用 CoreData。

I am from a .NET MVC background and would normally have my controller call through to a service layer (using a Repository Pattern) to return data that could be mapped to my View.我来自 .NET MVC 背景,通常会将我的 controller 调用到服务层(使用存储库模式)以返回可以映射到我的视图的数据。 This would work in a similar way to the traditional Business Logic and Data Access Layer.这将以与传统业务逻辑和数据访问层类似的方式工作。

However on the Mac most of my reading suggests that my Models and Controllers should share the responsibility of populating the Model with with data and undertake business and validation logic.然而,在 Mac 上,我的大部分阅读表明我的模型和控制器应该分担使用数据填充 Model 并承担业务和验证逻辑的责任。

This seems to me a little restrictive and goes against the DRY principle as I may need to repeat some data access/business logic operations in other models thus having to write tha same bit of code again.在我看来,这似乎有点限制,并且违反了 DRY 原则,因为我可能需要在其他模型中重复一些数据访问/业务逻辑操作,因此不得不再次编写相同的代码。

Therefore is it feasible to have a set of classes or external libraries that undertake business/data access logic (to a SQLite database) that can then be called from any controller?因此,拥有一组可以从任何 controller 调用的业务/数据访问逻辑(到 SQLite 数据库)的类或外部库是否可行? Therefore the Model will only contain data about itself and validation logic?因此 Model 将仅包含有关其自身和验证逻辑的数据? Or does this go against the core MVC principles and ways of building applications on the Mac?或者这个 go 是否违反了核心 MVC 原则和在 Mac 上构建应用程序的方式?

Is there a particular reason not to use Core Data in this scenario?在这种情况下是否有特别的理由不使用 Core Data? It's highly-optimized for persisting objects to and from the local filesystem.它针对与本地文件系统进行持久化对象进行了高度优化。 It also performs validation at the model level, results caching, notifications, etc.它还在 model 级别执行验证、结果缓存、通知等。

What you describe sounds like a good idea to me.你所描述的对我来说听起来是个好主意。 Putting your validation and business logic in your model classes is proper use of MVC, and having the data stored in an sqlite database (that the model classes talk to) is a commonly used methodology too.将验证和业务逻辑放在 model 类中是正确使用 MVC,并将数据存储在 sqlite 数据库中(model 类也是常用的方法)。

I'm not sure if we're on the same page with terminology: if you use that design, your classes "that undertake business/data access logic (to a sqlite database) that can then be called from any controller" will in fact be model classes.我不确定我们是否与术语在同一页面上:如果您使用该设计,那么您的类“承担业务/数据访问逻辑(到 sqlite 数据库)然后可以从任何控制器调用”实际上将model 类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM