Re:Data Classes for Java
by wvenable on Wednesday November 01, 2017 @10:53PM
(#15607470)
This seems to deny the fact that a lot of data exists to just be stored and displayed. Probably 85% of all software in the world has a "FirstName" field/property/column in it somewhere. What name you propose giving a method that changes that value?
[ Parent
| on HN ]
Re:Data Classes for Java
by HumanDrivenDev on Wednesday November 01, 2017 @11:13PM
(#15607546)
I guess I'd call it "changeLastName". That's closer to the domain, we don't go to the Department of Births, Deaths and Marriage and tell the clerk we want to "set" our last name. But that is being too pedantic, even for me.
I'll concede defeat. That is a pretty good example. At the end of the day, "customer details" class is actually a big bag of fields that needs some access control and validation.
If you get married, you might "changeLastName" or maybe even "rename" yourself but if you're just moving that name from one place to another you'd "set" it.
You could probably come up with lots of different names but none of them will be more clear than "set" in this case.
If moving requires a name to be set you are at constructor time, no need for permanently available setters.
Two things with that, you're assuming immutability but even a simple database entity object wouldn't be immutable. And secondly, anything over a handful of values and setting them via a constructor isn't pretty.
if it's just used for display, use a new value.
if there's more to the domain context, i'd call it rename(~). i think from the outside, it's better to articulate what you want in domain semantics, rather than implementation semantics.
Re:Data Classes for Java
by HumanDrivenDev on Wednesday November 01, 2017 @11:45PM
(#15607688)
i think from the outside, it's better to articulate what you want in domain semantics, rather than implementation semantics.
You've articulated here what I've actually been trying to communicate. I have no problem if a method does nothing but get/set a variable. I just think they should be named with domain semantics.