MVC Model对象,域对象和DTO之间有什么区别? [英] What is the difference between an MVC Model object, a domain object and a DTO

查看:845
本文介绍了MVC Model对象,域对象和DTO之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

MVC模型对象,域对象和DTO之间有什么区别?



我的理解是:



MVC模型对象:



模拟要由相应视图显示的数据。因此可能不会直接映射到域对象,即可能包含一个或多个域对象的数据。


  1. 客户端

  2. 可能包含业务逻辑,例如验证,计算属性等

  3. 无持久性相关方法

域对象:



在诸如Reservation,Customer,ORder等问题域中建立真实世界对象的对象用于持久存储数据。


  1. 服务器端

  2. 没有业务逻辑

DTO数据传输对象):



当层在不同的进程中时,用于在层之间传输数据的对象,例如从数据库到客户端应用程序。允许通过电线进行单个事务,而不是多个呼叫。 DTO只包含数据和访问器方法,没有逻辑。数据用于特定的数据库事务,因此可能不会直接引入域对象,即可能包含一个或多个域对象的数据。


  1. 双层通过层之间传递

  2. 没有业务逻辑

  3. 没有持久性相关的方法

所以问题:



(1)我的理解是否正确?我缺少一些关键点吗?



(2)假设Model对象不需要额外的业务逻辑,是否有任何理由不使用Domain对象作为MVC模型?



(3)假设Model对象不需要额外的业务逻辑,是否有任何理由不使用DTO作为MVC模型?



谢谢。



Tim

解决方案

域和模型对象基本相同,可能包含业务逻辑。根据实现,如果将业务逻辑从模型中删除到服务类中,则域和DTO对象可能相当。



通常,DTO的一个关键变体是View Model ,它纯粹用于在域模型和视图之间传输数据,尽管视图模型通常可能包含逻辑,尽管这应该是纯粹的UI逻辑。


What is the difference between a MVC Model object, a domain object and a DTO?

My understanding is:

MVC Model object:

Models the data to be displayed by a corresponding view. As such may not map directly on to a domain object, i.e. may include data from one or more domain objects.

  1. Client side
  2. May contain business logic, e.g. validation, calculated properties, etc
  3. No persistence related methods

Domain object:

Object that models a real world object in the problem domain like Reservation, Customer, ORder, etc. Used to persists data.

  1. Server side
  2. No business logic

DTO (Data Transfer Object):

An object used to transfer data between layers when the layers are in separate processes, e.g. from a DB to a client app. Allows a single transaction across the wire rather than multiple calls. A DTO contains just data and accessor methods, no logic. The data is for a particular DB transaction so may not may directly on to a domain object, i.e. may include data from one or more domain objects.

  1. Used on both sides as passed between layers
  2. No business logic
  3. No persistence related methods

So to the questions:

(1) Is my understanding correct? Am I missing some key points?

(2) Are there any reasons not to use Domain objects as the MVC Model assuming that the Model objects do not require extra business logic?

(3) Are there any reasons not to use DTOs as the MVC Model assuming that the Model objects do not require extra business logic?

Thanks.

Tim

解决方案

Domain and model objects are essentially the same, and may contain business logic. Depending on implementation, domain and DTO objects may be equivalent if you remove business logic from the model into a service class.

Often a key variant of the DTO is the View Model, which is used purely to transfer data between the domain model and the view, although often a View Model may contain logic, although this should be purely UI logic.

这篇关于MVC Model对象,域对象和DTO之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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