Jammer Posted December 21, 2017 Share Posted December 21, 2017 (edited) Suppose I have these three classes: Main (exchangesContext with BankTask), BankTask , Data (Data class contains methods which require api access) Let's say the BankTask needs to use some methods from the Data class. I realised that I need to call exchangeContext inside BankTask aswell but there's obviously no onStart method there. Should I let the Data class accept MethodProvider in its constructor instead or is it possible or even preferable to use exchangeContext in such cases? Edited December 21, 2017 by Jammer Quote Link to comment Share on other sites More sharing options...
Explv Posted December 21, 2017 Share Posted December 21, 2017 (edited) 56 minutes ago, Jammer said: Suppose I have these three classes: Main (exchangesContext with BankTask), BankTask , Data (Data class contains methods which require api access) Let's say the BankTask needs to use some methods from the Data class. I realised that I need to call exchangeContext inside BankTask aswell but there's obviously no onStart method there. Should I let the Data class accept MethodProvider in its constructor instead or is it possible or even preferable to use exchangeContext in such cases? You could always override the exchangeContext method to also exchangeContext with instances within your class: public class BankTask extends Task { SomeOtherClassThatNeedsApi someOtherClass = new SomeOtherClassThatNeedsApi(); @Override public MethodProvider exchangeContext(Bot bot) { super.exchangeContext(bot); someOtherClass.exchangeContext(bot); return this; } // ... Blah blah whatever } Or yes just pass MethodProvider as a parameter to the constructor of your other class. Or just add an onStart method to your base Task class and call it once before executing a Task. This may or may not be appropriate depending on what your "Task" pattern is. Edited December 21, 2017 by Explv 2 Quote Link to comment Share on other sites More sharing options...