Hi,

I wanted to post what I've done before I commit the code to get an idea if
this is the right approach.

Background: a circular dependency is when class A references class B which
references class B. Pretty simple.

In many of the FlexJS examples, there are circular dependencies between
the application class and the application's controller. For example,
DataBindingExampleApp references its controller, MyController, which has a
reference back to the application. Likewise, the TodoListSampleApp
references its controller which holds a reference to the app class. The
objective in both examples is provide the controller with a reference to
the model.

In both of these cases, my solution is to remove the explicit reference to
the application (eg, DataBindingExample) in the controller and replace it
with the Application class and then extract what it needs into local
variables. In these examples, the application object was being used just
to get to the model (and view in one case). For example in
DataBindingExample's MyController class:

public function MyController(app:Application=null) {
    if (app) {
        this.app = app as DataBindingExample;
        app.addEventListener("viewChanged", viewChangeHandler);
    }
}
then further down:
    MyModel(app.model).requestedField = field;

The simple solution is:

private var model:MyModel;
public function MyController(app:Application=null) {
    if (app) {
        app.addEventListener("viewChanged", viewChangeHandler);
        model = app.model as MyModel;
    }
}

and further down:
    model.requestedField = field;

This pattern removed the circular dependency in DataBindingExample and
TodoListSample.

However, MobileTrader is bit trickier. MobileTrader has several mobile
"views" and each has its own controller. The circular dependency in this
case is between these secondary views and their respective controllers.
The way I approached this was to make a new interface in the MobileTrader
example src, called "IBeadControllerWithModel" which extends
IBeadController and adds a getter/setter for a model. Now the view can
simple reference its controller using this new interface and set the model
so the controller can now modify it.

Let me know what you think of this approach and I'll update the code and
commit it thereafter.

Thanks,
‹peter


On 8/16/16, 10:58 AM, "Peter Ent" <[email protected]> wrote:

>Hi,
>
>I'm taking a look at circular dependencies and developing a pattern we can
>follow. I will be changing some (or all) of the examples to use this
>pattern. I'll repost here when I have something working.
>
>Regards,
>Peter Ent
>Adobe Systems/Apache Flex Project
>
>On 8/16/16, 3:06 AM, "PKumar" <[email protected]> wrote:
>
>>can you share some examples?
>>
>>
>>
>>-----
>>Regards,
>>Prashant
>>--
>>View this message in context:
>>http://apache-flex-users.2333346.n4.nabble.com/FlexJS-Circular-Dependency
>>-
>>tp13287p13313.html
>>Sent from the Apache Flex Users mailing list archive at Nabble.com.
>

Reply via email to