mardi 11 juin 2019

is it a bad practice to require as parameter from a service in ModuleA, a service located in ModuleB?

My questions other than if is possible or not is about, will it be redundant? or will I end up have a strong dependency between them? or anyways would be the same if I dont.

The problem:

I have two modules in a single project (gradle/kotlin)

Module A has its own services and works fine. Module B now requires to include module A to avoid duplicating code and then invoke a method from a service of module A.

So, on the constructor might look like this:

MyServiceModuleA( service myServiceModuleB) {
...
}

So I will be able to invoke them all...

Instead, if I want to stay "agnostic" about it I can receive as parameter all required fields to create my own MyServiceModuleB...

Lets say the constructor is like this

MyServiceModuleB(String name, String age, // other 4){
...
}

Then I would do:

 MyServiceModuleA( String name, String age, //other 4) {
    this.myServiceModuleB = new ServiceModuleB(name, age, ...);
  }

Is there any anti-pattern I should be aware or it and know which option to avoid?

Aucun commentaire:

Enregistrer un commentaire