If you want to solve the issue with dependencies and imports, you can use a Interface
set with a factory to avoid having to change code.
An example
Let's imagine that you have the following packages in main :
- main / model
- main / views
- main / controllers
- main / dao
- main / api
From the classes of the dependencies you have, you can extract methods in a Interface
. for examples of a BBDB Object you need:
package api
public interface IBdConexion{
public Map<String,Object> getQueryResult(Object[]... data);
public boolean connect(String host, String user, String password);
// ademas agregemos un método para ver si la conexión es posible.
public boolean puedeConectar();
}
Now you have the possibility to create two variants of a class that implements this interface:
- debug / dao / MiBdConexion.java
- release / dao / MiBdConexion.java
In debug you implement a class that has all the dependencies' imports:
package dao
import com.dependencia.uno.*;
import org.dependencia.dos.*;
public class MiBdConexion implements IBdConexion{
@Override
public Map<String,Object> getQueryResult(Object[]... data){
// implementación
}
@Override
public boolean connect(String host, String user, String password){
// implementación
}
@Override
public boolean puedeConectar(){
// implementación
}
}
In release another implementation without the imports:
package dao
public class MiBdConexion implements IBdConexion{
@Override
public Map<String,Object> getQueryResult(Object[]... data){
// implementación
}
@Override
public boolean connect(String host, String user, String password){
// implementación
}
@Override
public boolean puedeConectar(){
return false; }
}
Finally we can implement for example a way to get the implementation we need in main / controllers, without the need to change code in main:
public class MiConexionFactory{
public static IBdConexion getConexion(){
IBdConexion con = (IBdConexion) Class.forName("dao.MiBdConexion").newInstance();
return con;
}
}
The getConexion()
method will return the class corresponding to the build that implements the interface. So we can access all the methods we need via the interface without having to change the imports in the rest of the code.