Well I guess the point is that you shouldn’t need all these method calls to achieve simple goals. Most of those “getF” are calls to some SystemFactory to get a GenericObjectFactory and so on and so forth.
This just tells me you don’t use Java. Factory classes are just used to create objects in a standardized way, but this code isn’t creating anything, it’s just getting nested fields from already instantiated objects.
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?
Sure, but most of the lines in the screenshot break down to:
object1.setA(object2.getX().getY().getZ().getI().getJ().getK().getE().getF(i).getG().toString())
Aside from creating a method inside the class (which you should probably do here in Java too) how would another language do this in a cleaner way?
Well I guess the point is that you shouldn’t need all these method calls to achieve simple goals. Most of those “getF” are calls to some SystemFactory to get a GenericObjectFactory and so on and so forth.
This just tells me you don’t use Java. Factory classes are just used to create objects in a standardized way, but this code isn’t creating anything, it’s just getting nested fields from already instantiated objects.
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?