Design for using breadboard connection
I have a simple UI application with a backend connection from which I am fetching data. Now, during development, I would not want to connect to the backend as it slows me down. So, I have locally stored data and I 'mock' the connection to return locally stored data instead of calling the server.
Now it's not for writing test cases (hence I don't see if fake frameworks appear in the picture), but just the ability to switch between local and remote connection during development.
There are many ways to do this, I suppose:
- Getting a connection to a factory (or via dependency injection) and setting a flag that returns a local connection
- Maintaining a properties file where I have set 'local = true' or something similar which returns a local connection.
Are there other ways to achieve this?
source to share
There are two halves of the problem:
- Where does the app connect from? Factory? Smart annotations driving DI? ...
- How the connection source determines which one to use, mock, or possibly several different life options (Prod, ST, Dev, etc.).
For the former, there is a lot of discussion about DI techniques elsewhere. I would favor approaches that also included unit testing easily - I found DI to be useful in this context.
As for any properties / configurations that can be used, it depends on the type of environment you have. You are not saying if this is a standalone Java application or something running in a JEE framework. If the latter using JNDI resources might be helpful.
source to share
Have you looked into the framework of dependency injection?
I have Google Guice to deal with this exact problem.
source to share