I have multiple modules in my android project some of which depend on other modules however I have a couple of cases where modules depend each other thus creating a circular dependency?
How would you generally go about avoiding such cases in an android or java project? In my case I am using Intellij Idea 13.1.2 if that makes any difference?
Many thanks in advance.
To reduce or eliminate circular dependencies, architects must implement loose component coupling and isolate failures. One approach is to use abstraction to break the dependency chain. To do this, you introduce an abstracted service interface that delivers underlying functionality without direct component coupling.
The Mediator Pattern can also help to lift circular dependencies by encapsulating the bidirectional interaction of two or more objects. The downside of your current code is (besides the circular dependency), that whenever class A changes and also data persistence changes, you have to touch and modify class B.
Circular dependencies can be introduced when implementing callback functionality. This can be avoided by applying design patterns like the observer pattern.
To resolve circular dependencies: Then there are three strategies you can use: Look for small pieces of code that can be moved from one project to the other. Look for code that both libraries depend on and move that code into a new shared library. Combine projectA and projectB into one library.
You cannot design modules with circular dependency.If it persist you can merge the dependent code into single module to avoid circular dependency.
There is no magic. You need to redesign your model. Experience and application.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With