In the book GOOS. It is told not to mock values, which leaves me confused. Does it means that values don\'t have any behavior?
I dont\' much knowledge about the value ob
Not all immutable objects are value objects. By the way, when designing, consider that the ideal object has only immutable fields and no-arg methods.
Regarding the heuristic, a valid approach can be considering how objects will be used: if you build an instance, invoke some methods and then are done with it (or store it in a field) likely it won't be a value object. On the contrary, if you keep objects in some data structure and compare them (with .equals()
) likely you have a value object. This is especially true for objects that will be used to key Map
s
Value objects should be automatic-tested themselves (and tests are usually a pleasure to read and write because are straightforward) but there's no point in mocking them: the main practical reasons for mocking interfaces is that implementation classes
Neither apply to value objects.