什么是DTO和BO?有什么区别? [英] What is a DTO and BO? What is the difference?

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

问题描述

我知道DTO是数据传输对象,而BO是业务对象。但是,这实际上意味着什么?我什么时候应该选择一个?
据我了解,DTO仅用于传输数据,没有业务逻辑。这是否意味着DTO没有仅方法的任何属性(getter和setter)?但是,它仍然具有BO的属性。有人可以解释一下吗?谢谢。

I know DTO is a data transfer object and a BO is a business object. But, what does it actually mean? When should I choose one over the other? From, what I understand DTO is just used to transfer data and doesn't have business logic. Does this mean that a DTO doesn't have any method only properties(getter and setter)? But, it still has properties of a BO. Can someone please explain? Thanks.

推荐答案

DTO用于在层/层之间传输数据。为此,它不需要任何方法,有时甚至不需要任何方法,例如当DTO通过Web服务公开时。

DTO is used to transfer data between layers/tiers. For such purpose it doesn't need any methos and sometimes it even should not have any methods - for example when DTO is exposed over web service.

业务对象是一个聪明的对象,它包含数据和对该对象执行操作(更改数据)的方法。将BO暴露给上层时,它可以调用对象的公共方法。有时您不希望这样做,因此创建了仅提供数据但不提供方法的DTO。

Business object is clever object which contains data and methods which performs operations (change data) on this object. When you expose BO to upper layer, it can call your object's public methods. Sometimes you don't want this and for that reason you create DTO which only offers data but not methods.

DTO不必传输所有BO数据。当您遵循严格的DTO方法时,您将为业务层上公开的每个操作创建特定的DTO。例如,如果您的对象具有审核数据(例如CreatedBy,ModifiedBy,CreatedDate等),而您正在创建Update方法,则传入的DTO(具有更新的对象)不需要具有这些属性,因为上层无法修改它们-只有业务逻辑可以

DTO doesn't have to transport all BO data. When you follow strict DTO approach you create specific DTOs for each operation exposed on your business layer. For example if your object has audit data like CreatedBy, ModifiedBy, CreatedDate, etc. and you are creating Update method your incomming DTO (with updated object) doesn't need to have these properties because upper layer cannot modify them - only business logic can.

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

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