There is a heuristic called the Law of Demeter (LoD) or Principle of Least Knowledge that says a module should not know about the innards of the objects it manipulates. More precisely, the method of a particular class should call:
So the following Java code appears to violate the Law:
String output = obj.getContext().getOptions().getDir().getPath();
It’s easy to forget something around this train structure.
In order to solve the issue consider encapsulating the logic:
String output = obj.getPathFromContext();
More on programming basics.
Senior Software Engineer developing all kinds of stuff.