Using setters to do anything else, but set the value transparently, violates the principle of separation of problems: with this design, you constantly interlace the configuration problem with care about pruning. This is all wonderful and attractive if you are 100% sure that you will never, for the whole life of your program, have as a single use case where you want to install without cropping. As soon as you need it, the failure mode of this project is rather pathetic: you will have the usual set method, which is actually βspecialβ, and it will have to add another setWithoutTrimming method, exactly the opposite of any sane assumption for a new programmer.
More generally, my choice is to use pure public fields (Hibernate supports them, as well as Spring, Jackson, etc.), which makes the semantics of determining their dead clarity. If I have another problem, such as cropping, then I use an explicit call to the static method (pure function), which does the necessary conversion. This leads to a clear and obvious design without any WAT, such as "why does the getter return a different value from what I just set?".
Marko topolnik
source share