So i have this challenge as below.
I have gradle project structure.
-
Main Project
-- a. Android(#Sub-Project 1)
-- b. Commons(#Sub-Project 2)
-- c. Http-Comms(#Sub-Project 3)
Summary I have a 3 projects as above. HTTP-Comms has to be independent, it has dependency on the Commons project. HTTP-Comms has a interface and implementor which exposes the methods to start and stop the server. Problem is i have a reference of HTTP-Comms project in Android and want to decouple this. So that a normal build can run without this feature and a developer build will run with this feature. If i will not include this project in distribution for a normal build, Android will fail because of ClassNotFound ..
Briefly explained Now this HTTP-Comms project has a NanoHttpdServer implementation and has many classes which reference libraries related to server and other utility classes. Its independent on its own. We have a interface IHttpComms which has methods to start and stop the server
interface IHttpComms{
public void startServer();
public void stopServer();
public void serveRequest();
}
class Controller implements IhttpComms{
//Implements the feature
// reference to other classes in the HTTP-Comms project.
}
Now There is another Android project which has action button to Start and Stop the server. So it depends on HTTP-Comms project. Here i am doing
IhttpComms comms = new Controller();
hence making a tight coupling between the HTTP-Comms and Android project.
Where as Commons project can be referred and should have the common code between these projects. But Commons project cannot hold reference to HTTP-COMMS
Now as HTTP-Comms is a incubating feature for us, we require it not to be part of the build process at some times.
My Question is ...
-
Can i use any dependency injection framewroks, and i will stil be able to inject the dependent object outside the project. ?? Like have a instance of Controller and inject to Android ?
-
Without DI frameworks.. any other design pattern solution ?
Aucun commentaire:
Enregistrer un commentaire