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
API Support
Post subject: Re: IContext context - best practices to use in other classes than the IStrategy
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); } }
sinusgamma
Post subject: Re: IContext context - best practices to use in other classes than the IStrategy