I m reading the "Clean Code book", and, in paralel, I m working on calisthenic objects Kata like the banker account, and I m stuck on that rule :
The 9th rule of calisthenic objects is that we don't use getter or setters.
It seems pretty fun, and I agree with this principle. Moreover, at page 98-99 of Clean Code, the author explains that getters / setters break abstraction, and that we don't have to ask our object, but we have to tell our object.
This makes perfect sense in my mind, and I fully agree with this principle. The problem comes in practice.
For example, I m having an application in which I have to list some users, and to display the user details.
My user is composed of :
-> Name --> Firstname --> String --> Lastname --> String -> PostalAddress --> Street --> String --> PostalCode --> String
How can I do, or what can I do to avoid getters when I only need to display a simple information (and I have to confirm that I don't need extra operation on that particular field) to display the Firstname value in a simple (random) output support ?
What comes up in my mind
One solution is to make :
Which is totatally terrible, breaking many rules of calisthenic objects, and breaking the Demeter Law.
Another one would be something like :
String firstName = user.provideFirstnameForOutput(); // That would have called in the user object => String firstName = name.provideFirstnameForOutput(); // That would have called in the name object => String firstName = firstname.provideFirstnameForOutput();
But I don't feel comfortable with this solution, that only seem to be a "higher order accessor" like bypassing standard getter/setter with a method that only aims to match Demeter law...
Any idea ?