I am currently making my method call in the following way:
InstrumentsInfo instrumentsInfo = new InstrumentsInfo();
String shortInstruName = "EURUSD"
TrackInstruments trackInstruments = new TrackInstruments(instrumentsInfo.getInstrumentID(shortInstruName), instrumentsInfo.getInstrumentTickSize(shortInstruName), instrumentsInfo.getInstrumentName(shortInstruName));
In VBA I would do something like this
With instrumentsInfo
TrackInstruments(.getInstrumentID(shortInstruName), .getInstrumentTickSize(shortInstruName), .getInstrumentName(shortInstruName));
So my question is, is there a way to avoid repeating “instrumentsInfo” in the method call in Java?
In a word no although you may want to consider changing
to
and then have the constructor take the parameters it needs.
Or perhaps use the builder pattern if you need a lot of parameters.
Or indeed ask yourself why you are constructing
InstrumentsInfooutside theTrackInstrumentswhen the latter seems to rely on it so heavily. (Without fully understanding your objects that is)