从应用角度来看,传输对象本身应该符合值对象(value objects)的要求,即该对象所对应的类是 不可变类 ( immutable classes ),这样可以保证各层使用数据时不会因误操作而引发领域模型的变化。
基于20个网页-相关网页
One advantage of immutable classes is that they are thread-safe.
(不可变类的一个优点就是它们是线程安全的)。
Finally, one of the best features of immutable classes is how well they fit into the composition abstraction.
最后要说一点,不可变类最酷的一个地方是,它们融合到复合(composition) 抽象中的能力是如此之强。
Making the message classes immutable and cloning mutable references such as arrays at construction time would have prevented this problem.
使得消息类不可变并在构造时克隆像数组这样的可变引用,就可以防止该问题。
应用推荐