aino-komal / mvp4g

Automatically exported from code.google.com/p/mvp4g
0 stars 0 forks source link

Parent child circular depedency #22

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
If we have a GWT project that is divided into several GWT modules (and each
of these module is modeled as mvp4g module). These modules have inheritance
say Module B include Module A. So for firing some event from Module A to
Module B, former gets a dependency on latter causing a circular dependency.

Is there any way in the current framework to get rid of this problem?

Original issue reported on code.google.com by agg.mo...@gmail.com on 17 Feb 2010 at 11:30

GoogleCodeExporter commented 9 years ago
If I get this right, in GWT config file of ModuleA, you need to add ModuleB and 
in 
GWT config file of ModuleB, you need to add ModuleA, which leads to a circular 
dependency, right?

If it's your problem, the only way I see to solve your issue it's to put your 
Mvp4g 
module interface for ModuleB (I'm guessing it's the parent) inside another GWT 
module. Then in GWT config file of ModuleA, you will have the ModuleC and in 
GWT 
config file of ModuleB, you need to add ModuleA and ModuleC. You will then have 
no 
more circular dependency. I know it's not perfect because that's the only 
solution I 
see.

But maybe you were talking about another type of dependency?

Original comment by plcoir...@gmail.com on 18 Feb 2010 at 3:24

GoogleCodeExporter commented 9 years ago
Let me explain the problem in a bit more detail.

There are 2 GWT projects:

1. Company (Company.gwt.xml)
2. Department (Department.gwt.xml)

Both these projects uses mvp4g to make 2 modules - Comp inside 'Company' & Dept
inside 'Department'.

Company wide functionality in kept in 'Company' project. 'Department' project
includes 'Company' project in its gwt xml file and uses its classes also. So 
this
result in java dependency of 'Company' on 'Department'.

Now, in the application, there is menu (painted by 'Company') which contains 
link to
the department. So, when the user clicks on that link, the event bus of 
'Company'
sends event to the presenter (say DeptPresenter) of the Department. The 
configuration
of 'Company' event bus looks like:

public interface CompanyEventBus extends EventBus{

  @Event(handlers = DeptPresenter.class)
  void salesLinkClicked();
}

The above configuration requires a java dependency of 'Department' on 'Company'
causing the circular dependency.

I hope the above example explains the problem.

Is there any way to get rid of this circular dependency?

Original comment by agg.mo...@gmail.com on 24 Feb 2010 at 8:57

GoogleCodeExporter commented 9 years ago
So your RootModule (Top Module) is 'Department' and one of its child is 
'Company'. 

To actually forward event from child to parent, you need to do this:

public interface CompanyEventBus extends EventBus{

  @Event(forwardToParent = true)
  void salesLinkClicked();
}

and then

public interface CompanyModule extends Mvp4gModule{

       //since the Department is the RootModule, 
       //then it's associated module is Mvp4gModule
       public void setParentModule(Mvp4gModule module)
}

With this configuration, there is no circular dependency since CompanyModule 
doesn't 
know any class of Department module.

Also be careful, by doing this:
public interface CompanyEventBus extends EventBus{

  @Event(handlers = DeptPresenter.class)
  void salesLinkClicked();
}

You actually create its own instance of DeptPresenter for the CompanyModule. 
Modules 
don't share presenters.

Original comment by plcoir...@gmail.com on 25 Feb 2010 at 12:45

GoogleCodeExporter commented 9 years ago
With the new way parent/child configuration has been set, the child module 
doesn't have to know the parent module so there is no more circular dependency.

Original comment by plcoir...@gmail.com on 13 Sep 2010 at 5:18

GoogleCodeExporter commented 9 years ago

Original comment by plcoir...@gmail.com on 13 Sep 2010 at 5:18