3 ms·
Values are stateless and immutable, objects are stateful and mutable. Strictly speaking, the term 'Value Object' is an oxymoron. Unfortunately, in Java you can
by ExpiredLink 15y ago
Values are stateless and immutable, objects are stateful and mutable. Strictly speaking, the term 'Value Object' is an oxymoron. Unfortunately, in Java you can define values only in terms of classes and objects which leads to continuous confusion. The distinction between values and objects remains unclear for most Java developers.
- bunderbunder 15y agoIn the first research forays into what became OOP, objects were conceived of as being immutable by definition. That quickly went by the wayside as it ran up against a number of practical hurdles. But even then, in earlier true OOP languages such as Smalltalk there was simply no distinction between values and objects. In classic OOP, everything is an object, period. Later on, languages such as C++ and Java muddied the waters (imo) by throwing their own distinctive interpretations of what it means to be object-oriented into the ring. One of these 'innovations' was the idea that values and objects are somehow distinct. This idea has nothing to do with OOP orthodoxy and, everything to do with C++ maintaining a strong semantic distinction between the procedural type system it inherited from C and the object-oriented type system it introduced. Java simply followed C++'s lead on that front, albeit unnecessarily since Java lacks the characteristic (linking with C binaries) that motivated that feature in C++. Thus, there was an incredibly popular language which advertised itself as object-oriented, but featured wooly non-standard (for OOP) semantics for no apparent reason. Which naturally invites some retconning. Hence the idea that the concept of objects is anything but purely orthogonal to the distinction between value and reference semantics. Without such stories, one is stuck with the more historical story that a central, but often obnoxious and confusing (for learners, at least) feature of the two most popular languages in current usage is simply a hack in one case, and a foolish consistency in the other.