【发布时间】:2014-03-17 14:20:22
【问题描述】:
我正在研究 3 层架构,但我遇到了一个我似乎无法真正找到解决方案的问题。尽管网上有很多关于三层架构的文章,但都没有提到数据模型。除了在 MVC 的上下文中。
我有以下架构:
所以我们在这里看到的是每一层都使用数据模型。假设我有一个订阅的新用户:
UI : * Get the data from the http request
* Build a `UserModel()` with this data
* Pass this `UserModel` to the application layer
APP: * Pass the `UserModel` to the DB layer
DB : * Format the `UserModel` to SQL and write to DB.
因此,所有层都有效地具有此数据模型的概念。我想知道这是否真的是重点?
相反,假设我想解决这个问题,我可以让 UI 将“原始”数据(即字符串格式的用户值)传递给应用程序层。应用层将是唯一具有 UserModel 概念的层。因此,它将使用此数据创建UserModel。在没有模型概念的数据库层的情况下,我将如何继续将其传递给数据库层是很棘手的。所以我不知道该怎么做。
简而言之,我很困惑。非常感谢任何帮助。
【问题讨论】:
-
该模型跨越所有层,除非您引入 DTO。
-
它们基本上是跨项目共享层的一部分
标签: design-patterns n-tier-architecture three-tier