Dukascopy
 
 
Wiki JStore Search Login

Attention! Read the forum rules carefully before posting a topic.

    Try to find an answer in Wiki before asking a question.
    Submit programming questions in this forum only.
    Off topics are strictly forbidden.

Any topics which do not satisfy these rules will be deleted.

IContext context - best practices to use in other classes than the IStrategy
 Post subject: IContext context - best practices to use in other classes than the IStrategy Post rating: 0   New post Posted: Thu 27 Jul, 2017, 09:06 
User avatar

User rating: 2
Joined: Tue 11 Jul, 2017, 09:30
Posts: 24
Location: HungaryHungary
Hi, i know this is a newbie question, but I try to build a strategy with multiple classes, and I would like to know which is the best way to pass the IContext context to the other classes?

So far I passed the IContext context as an argument to the constructor of the new object instantiated in the Istrategy class. But this way I have to do this with all my classes. Maybe there are better solutions? Can Icontext context be static, does it have some danger?

Thanks


 
 Post subject: Re: IContext context - best practices to use in other classes than the IStrategy Post rating: 0   New post Posted: Thu 27 Jul, 2017, 11:29 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Each time a strategy is executed it gets unique IContext instance.
The strategy could use some kind of Builder to build your classes.
    class Builder {
        IContext context;

        // called from IStrategy.onStart
        void insertContext(IContext context) {
            this.context = context;
        }

        // called when objects are instantiated
        void buildClasses() {
            MyClass1 myClass1 = new MyClass1(context);
            MyClass2 myClass2 = new MyClass2(context);
        }
    }


 
 Post subject: Re: IContext context - best practices to use in other classes than the IStrategy Post rating: 0   New post Posted: Thu 27 Jul, 2017, 17:17 
User avatar

User rating: 2
Joined: Tue 11 Jul, 2017, 09:30
Posts: 24
Location: HungaryHungary
ok, thanks


 

Jump to:  

  © 1998-2025 Dukascopy® Bank SA
On-line Currency forex trading with Swiss Forex Broker - ECN Forex Brokerage,
Managed Forex Accounts, introducing forex brokers, Currency Forex Data Feed and News
Currency Forex Trading Platform provided on-line by Dukascopy.com