November 2002
Intermediate to advanced
240 pages
5h 9m
English
If I have an integer and I add 1 to it, I don’t expect the original integer to change, I expect to use the new value. Objects usually don’t behave that way. If I have a contract and I add one to its coverage, then the contract’s coverage should change (yes, yes, subject to all sorts of interesting business rules which do not concern us here).
We can use objects as values, as we are using our Dollar now. The pattern for this is Value Object. One of the constraints on Value Objects is that the values of the instance variables of the object never change once they have been set in the constructor.
There is one huge advantage to using Value Objects: you don’t have to worry about aliasing problems. Say I have one check and ...