2

Is it ok to design DTOs/parameter wrapper objects as inner classes? Is it common practice or does it have any major drawbacks? E.g:

//I want to initiate threads with parameters
public class TradeBot implements Callable<TradingReport> {

//I have a few parameters, so I decided to wrap those into an object
TradeBotParamDTO params;

//the wrapper for parameters is actually an inner class:
public class TradeBotParamDTO {
    JsonNode config;
    Instrument instrument;
    TimeframeBarMQL tf;
    int numberOfBars;
    int port;
    String host;

}

//Constructor to instantiate the Runnable with parameters
public TradeBot(TradeBotParamDTO params) {
    super();
    this.params = params;
}


@Override
public TradingReport call() {
//access params here...
params.getXXX()
... 
}
}
terrenceH
  • 41
  • 4
  • 1
    If the wrapper object isn't used anywhere else, I see nothing wrong with it, other than the fact that your classes might end up a bit big and bloated. Have you considered the Builder pattern (https://dzone.com/articles/design-patterns-the-builder-pattern)? – Riaan Nel Dec 19 '19 at 06:48
  • Related: https://stackoverflow.com/a/19826278/1371329 – jaco0646 Dec 20 '19 at 19:47

0 Answers0