What is a DTO and BO? What is the difference?

匆匆过客 提交于 2019-12-05 00:36:59

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.

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 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.

Generally, DTO has relative static data for that moment before arrive tier, but BO can dynamically keep state and flow flag value; and BO also could be self contained to have validation or logically reorganization or judgement for some business logic; but DTO 's change depends on tier 's change of data that passed over... But, BO's changes has wider scope, for example , depends on more dynamically update with business flow state, flag 's change, even the identity could be changed in real time , these suppose to be captured and acted to reflect from BO, for example, such as balance from $200 become zero , or balance from $2000 to $5000, then the deal/trade identity or status will change ... this is big difference between DTO and BO .

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!