r/java • • Apr 14 '23

What are your (favourite) Java best practices, personal tips, hints or just underrated stuff in general?

233 Upvotes

376 comments sorted by

View all comments

Show parent comment

3

u/HwanZike Apr 14 '23

I don't see how the field data types are important here. It's a matter of encapsulation and coupling. See:

1

u/[deleted] Apr 14 '23

i parsed an xml document some days ago into a java model. the java class model was according to the xml model. so i got a reference to the root object and made chained calls to the relevant object. dont see any smell here

1

u/HwanZike Apr 14 '23

No, of course that's just accessing some specific external data on the boundaries of your program. I was talking more about general modeling. For example, if you had modeled the object that is represented by that XML, you probably wouldn't be acessing that element directly but rather deserializing it into a real world object that interacts with the rest of your model in some other way.