`
d02540315
  • 浏览: 31395 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
最近访客 更多访客>>
社区版块
存档分类
最新评论

Value Object vs. Data Transfer Object (VO vs. DTO)

阅读更多
The pattern which is known today as Data Transfer Object was mistakenly (see this definition) called Value Object in the first version of the Core J2EE Patterns. The name was corrected in the second edition of the Core J2EE Patterns book, but the name "Value Object" became very popular and is still used as an alias for the actual DTOs. There is, however, a real difference between both patterns:

   1. A Data Transfer Object (DTO) is just as stupid data container which is used to transport data between layers and tiers. It mainly contains of attributes. Actually you can even use public attributes without any getters / setters, but this will probably cause too much meetings and discussions :-). DTOs are anemic in general and do not contain any business logic. DTOs are often java.io.Serializable - its only needed if you are going to transfer the data across JVMs.
   2. A Value Object [1,2] represents itself a fix set of data and is similar to a Java enum. A Value Object doesn't have any identity, it is entirely identified by its value and is immutable. A real world example would be Color.RED, Color.BLUE, SEX.FEMALE etc.

Data Transfer Objects are widely overused and the "real" Value Objects a bit unattended. Most developers who use the term Value Object actually have in mind DTOs. 


Original:  http://www.adam-bien.com/roller/abien/entry/value_object_vs_data_transfer
分享到:
评论
1 楼 0000ps 2009-12-24  
今天在MSDN上看到一段内容:
Value Object. Some books refer to Data Transfer Object as Value Object. This usage is no longer considered correct. For more information, see Patterns of Enterprise Application Architecture [Fowler03].
觉得很奇怪(感兴趣), 就查了下Value Object到底是什么.... 就到你这来了

MSDN全文:
http://msdn.microsoft.com/en-us/library/ms978717.aspx

相关推荐

Global site tag (gtag.js) - Google Analytics