编程语言
首页 > 编程语言> > java-术语“值对象”的词源/含义是什么?

java-术语“值对象”的词源/含义是什么?

作者:互联网

我是具有.NET / PHP背景的程序员.

我最近查看了有关Flashbuilder 4 / ActionScript的视频培训.视频培训中的视频之一称为“使用值对象创建数据模型”.我提到“价值对象”对我来说是一个陌生的术语,并不真正知道他是否意为“模型”,这有点令人困惑,因为我只能将其理解为“模型”,但标题却暗示我们正在使用值对象创建模型,表明它们是两个不同的实体.

培训师说,他被告知这是Java中一个相当普遍的术语,有时也称为“传输对象”.实际上,Wikipedia页面上的“值对象”重定向到“数据传输对象”,并且像this one这样的stackoverflow问题提到“值对象”也可能是“ Java中的映射对象”.

该术语的词源是什么?它与其他与数据模型相关的术语有何关系?它是否来自Java世界,并且在某个时候没有广泛使用吗?

解决方法:

在不同的上下文中,该术语似乎过载. Misko Hevery describes我解释这个术语:

An Injectable class can ask for other Injectables in its constructor. (Sometimes I refer to Injectables as Service Objects, but that term is overloaded.) […] Here are some examples of classes I would expect to get from my DI framework: CreditCardProcessor, MusicPlayer, MailSender, OfflineQueue.

Similarly Newables can ask for other Newables in their constructor, but not for Injectables (Sometimes I refer to Newables as Value Object, but again, the term is overloaded). Some examples of Newables are: Email, MailMessage, User, CreditCard, Song. If you keep this distinctions your code will be easy to test and work with. If you break this rule your code will be hard to test.

我同意的另一种描述是http://c2.com/cgi/wiki?ValueObject的描述

Examples of value objects are things like numbers, dates, monies and strings. Usually, they are small objects which are used quite widely. Their identity is based on their state rather than on their object identity. This way, you can have multiple copies of the same conceptual value object.

So I can have multiple copies of an object that represents the date 16 Jan 1998. Any of these copies will be equal to each other. For a small object such as this, it is often easier to create new ones and move them around rather than rely on a single object to represent the date.

A value object should always override .equals() in Java (or = in Smalltalk). (Remember to override .hashCode() as well.)

标签:terminology,value-objects,nomenclature,java
来源: https://codeday.me/bug/20191105/1997445.html