4 ms·
Did anyone else do a "double take" (what the...?) when they read this part: <<[the Value Object] has the following properties: Immutable, ..., Extensible>> ???
by throwaway2037 4y ago
Did anyone else do a "double take" (what the...?) when they read this part: <<[the Value Object] has the following properties: Immutable, ..., Extensible>> ???
I'm confused. How can an immutable object be extensible?
In Java parlance, would that mean something like:
public /*not final!*/ class GinormousData {
// all public final immutable members
public final String name;
public final int name;
...
}
Then, you are supposed to extend it? Weird. I never saw this style once. Is it a good idea?
The scary part, since the class is not final, you need to constantly worry if someone did something crazy like inherit and add mutable fields. Then legacy code that operates on references of GinormousData is clueless.
If I need to compose value objects, I would do this:
public final class GinormousData {
// all public final immutable members
public final String name;
public final int name;
...
}
public final class EvenBiggerData {
public final GinormousData gdata;
// other public final immutable members
}
Regardless of my language concerns above, this is great new feature for Ruby.
When I write Python, I go wild with namedtuples and dataclasses(frozen=True). Love them immutable data objects -- so easy to reason about when reading code.
- lolinder 4y agoI don't know why you're being downvoted so hard—I've never seen a definition of values objects that includes extensibility. I'm not even really sure what the point would be with the way they're typically used.