3层架构样式(包括MVC)中的DAL,DTO和DAO有什么区别 [英] What is the difference between DAL, DTO and DAO in a 3 tier architecture style including with MVC

查看:1144
本文介绍了3层架构样式(包括MVC)中的DAL,DTO和DAO有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,我正在学习ORM(对象关系映射)和3层体系结构样式(表示,业务和数据持久性). 如果我理解正确,我可以将数据持久层分为DTO和DAO层.

Recently I was learning about ORM (Object Relational Mapping) and the 3 tier architecture style (presentation,business and data persistence). If I understand correctly, I can separate the data persistence layer into DTO and DAO layer.

我想了解以下各部分如何在数据持久层中协同工作.

I would like to understand, how the following parts works together in a data persistence layer.

  • DAL(数据访问层)
  • DTO(数据传输对象)
  • DAO(数据访问对象)

最重要的是,我了解到

在较大的应用程序中,MVC仅是N层的表示层 建筑.

In larger applications MVC is the presentation tier only of an N-tier architecture.

我真的很困惑,例如在3层体系结构样式中怎么可能,其中MVC只是表示层,而DTO,DAO,DAL只是数据持久层的一部分.我完全迷路了.

I got really confused, how it can be even possible for example in a 3 tier architecture style where the MVC is the just a presentation tier, and the DTO, DAO, DAL is just a part of data persistence tier. I'm totally lost.

如果有人告诉我它如何一起工作的真相,我会感到很高兴.

I'd be glad if someone tell me the truth about how does it works together.

请不要结束这个问题,因为有很多不同的表达式,在大型应用程序中,这些东西基本上都是相互关联的,我到处都可以看到它,而且我无法想象它是如何工作的.

Please don't close this question because the many different expressions, I saw it everywhere these things are related to each other basically in big applications and I can't imagine how does it works.

我很感谢您的回答!

推荐答案

让我们从每个目的开始:-

Lets start with purpose of each: -

DTO

数据传输对象.这些通常用于将数据从控制器传输到客户端(JS).该术语还用于POCO/POJO的人很少,实际上保存了从数据库检索到的数据.

Data Transfer Objects. These are generally used to transfer data from controller to client (JS). Term is also used for POCOs/POJOs by few which actually holds the data retrieved from Database.

DAO

数据访问对象是用于实现DAL的设计模式之一.这将在数​​据库上构建并执行查询,并使用查询对象",数据映射器"等各种其他模式将结果映射到POCO/POJO.可以使用存储库"模式进一步扩展DAO层.

Data Access Object is one of the design patterns used to implement DAL. This builds and executes queries on database and maps the result to POCO/POJO using various other patterns including 'Query Object', 'Data Mapper' etc. DAO layer could be further extended using 'Repository' pattern.

DAL

数据访问层使用DAO/存储库/POCO等抽象您的数据库活动.ORM可以帮助您构建DAL,但也可以不使用DAL来实现它.

Data Access Layer abstracts your database activities using DAO/Repository/POCO etc. ORMs help you to build your DAL but it could be implemented without using them also.

MVC

模型视图控件是一种模式,用于将视图(表示)与业务逻辑分开.对于MVC,是否实现DAL无关紧要.如果未实现DAL,则数据库逻辑只会进入您的模型,这不是一个好方法.

Model View Control is a pattern which is used to separate view (presentation) from business logic. For MVC, it does not matter if DAL is implemented or not. If DAL is not implemented, database logic simply go into your model which is not a good approach.

在较大的应用程序中,MVC仅是N层的表示层 建筑.

In larger applications MVC is the presentation tier only of an N-tier architecture.

如上所述,模型消耗了您的大多数业务逻辑.在N层应用程序中,如果出于跨应用程序/平台的可重用性的目的而将业务逻辑完全分开,则MVC中的模型称为贫血模型".如果不需要在应用程序中以这种规模重复使用BI,则可以使用Model来保留它.没有混乱,对吧?

Models consume most of your business logic as stated above. In N-tier application, if business logic is entirely separated for the purpose of re-usability across applications/platforms, then Models in MVC are called anemic models. If BI need not to be re-used at that scale in your application, you can use Model to hold it. No confusion, right?

如果有人告诉我它是如何工作的,我会很高兴 在一起.

I'd be glad if someone tell me the truth about how does it works together.

所有MV *模式仅定义想法/概念;他们没有定义实现. MV *模式主要着眼于将视图与BI分开.只是专注于此.

All MV* patterns define the idea/concept only; they do not define implementation. MV* patterns mainly focus on separating view from BI. Just concentrate on this.

请参阅答案,以获取有关保存数据的不同对象的详细信息.

Refer this answer for details about different objects holding data.

这篇关于3层架构样式(包括MVC)中的DAL,DTO和DAO有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆