Jump to content

ExchangeContext or pass Script instance


Jammer

Recommended Posts

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 by Jammer
Link to comment
Share on other sites

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 by Explv
  • Like 2
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...