0

Assume:
I have a Java/Android modular library that can setup like this:

package com.mycorp.app.sample.integration;
public class ModuleConnector {

    public static final LogcatLogger   LOGCAT_LOGGER              
        = new LogcatLoggerImpl.Configurator("TEST")
              .verbosity(LogcatLoggerImpl.Verbosity.VERBOSE)
              .replace("ApiDesign", "Design")
              .replace("Sample", "Sample")
              .createInstance();

    public static final JsonWebservice GET_INFORMATION_WEBSERVICE
        = new JsonWebserviceImpl.Configurator()
              .logger(LOGCAT_LOGGER)
              .enableCaching(true)
              .endpoint("http://test.com")
              .createInstance();
}


Problem:
Current dependency diagram shows: has no dependency. it's ok

after adding this code shows below

package com.mycorp.app.sample.global;
public class G extends Application {

    static {
        ModuleConnector.GET_INFORMATION_WEBSERVICE.request(null);
    }
}


I want to prevent marked dependency: the problem

Notes:

  • ModuleConnector is in com.mycorp.app.sample.integration package
  • com.mycorp.app.sample.global can be every client side package.
  • I want to use com.mycorp.app.sample.integration to access module apis
  • I have alot of api methods, so i prefer to don't use from Command/Strategy pattern
Behnam
  • 2,212
  • 2
  • 22
  • 32

2 Answers2

0

Is this a puzzle? Your code does not show what the dependency is. Is a compile-time or run-time dependency? What kind of analysis produced your diagram?

With the information you are providing, it's not possible to tell what the dependency is, and how to prevent it.

Tom
  • 1,414
  • 12
  • 21
  • No! Source of dependency is absolutely visible. When `ModuleConnector.GET_INFORMATION_WEBSERVICE` call `request` method that is defined in `com.mycorp.lib.invoker.api`, a dependency to this package will create. The diagram produced with **STAN4j**. – Behnam Aug 05 '12 at 22:15
  • What I meant is that it is not visible from the code you provided. Now that you have explained that the GET_INFORMATION_WEBSERVICE is defined in com.mycorp.lib.invoker.api, it is clear that this is causing the dependency. – Tom Aug 07 '12 at 07:14
  • `GET_INFORMATION_WEBSERVICE` defined in `com.mycorp.app.sample.integration` ( see source code 1 ), but `request` defined in `com.mycorp.lib.invoker.api`. and the dependency created just for calling `request`. – Behnam Aug 07 '12 at 07:27
0

The scenario is not very clear...but i am trying to give some idea

perhaps you want to remove this direct dependency so that u can provide your lib as separate jar file...in that case you can put some wrapper in "integration" module

App -> Integration/Plugin module -> Your library module

Like, when you called ModuleConnector class, you need to initialize it in static method, so your developer must have to know, that "before using ModuleConnector, i must initialize it in a static method....that I must not forget"....if want to remove this kind of dependency, then you can provide

  package com.mycorp.app.sample.integration;

  Class ApplicationModuleConnector  {
    ModuleConnector connector;
    static {
       //do something
    }

    //this method will be called by you developer, he need not to bother about init() of ModuleConnector
    public invokeWebservice() {}
  }
Abhishek Chatterjee
  • 1,962
  • 2
  • 23
  • 31
  • Thanks for answer, but as I mentioned, I have alot of api methods and signetures, so it's not good idea to define api in ApplicationModuleConnector again for each module in library system. – Behnam Aug 06 '12 at 05:50