• Anomandaris@kbin.social
    link
    fedilink
    arrow-up
    9
    ·
    edit-2
    1 year ago

    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?

    • Blackthorn@programming.dev
      link
      fedilink
      arrow-up
      3
      ·
      1 year ago

      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.

      • Anomandaris@kbin.social
        link
        fedilink
        arrow-up
        2
        ·
        1 year ago

        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.

    • bleistift2@feddit.de
      link
      fedilink
      English
      arrow-up
      2
      ·
      1 year ago

      You shouldn’t reach through an object to invoke a method. That tightly couples the classes which getJ and getG (for instance) return.

      • Anomandaris@kbin.social
        link
        fedilink
        arrow-up
        1
        ·
        1 year ago

        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?