That is an interesting point, but it’s not Java specific, you could do this exact thing in most other languages and it would look pretty much the same.
Considering the fact that in a lot of enterprise projects the data structures are not necessarily open to change, how would you prevent reaching through objects like this?
You shouldn’t reach through an object to invoke a method. That tightly couples the classes which getJ and getG (for instance) return.
That is an interesting point, but it’s not Java specific, you could do this exact thing in most other languages and it would look pretty much the same.
Considering the fact that in a lot of enterprise projects the data structures are not necessarily open to change, how would you prevent reaching through objects like this?