Java Design Pattern
Instead of manipulating your code with an "if" statement, you should write an interface that defines all the methods needed to communicate with the server, and reference that interface instead of a specific implementation. Then, your "dummy data" implements this interface.
The advantage of this is that your code will be written in a way that is independent of the server implementation. This will allow you to modify data on the server without changing the client implementation.
source to share
You need a data access object, or an object that acts as a proxy between the requesting program and the data.
You ask the DAO for data and based on its configuration, it responds with your server data or other data. Other data could be new instances of classes, data from text files, etc.
In this image , "Business Object" is your program, "Data Access Object" is a reconfigurable gatekeeper, Transfer Object "is an object representation of the requested data, and" Data Source "is the interface you previously used for data access When the Data Access Object is in place, it's easy to add code to it to “select” the correct data source (DummyDataSource, FileDataSource, JDBCDataSource, etc.).
source to share
I would recommend using the store pattern to encapsulate your data layer. Create an interface for the repository and create two concrete implementations, one for dummy data and one for server data. Use the Factory pattern to create your repository. Factory will return the correct concrete Repository implementation based on whether you are connected or not.
source to share
Proxy_pattern is the best fit for your use.
In short, a proxy is a wrapper or agent object invoked by the client to access the real service object behind the scenes.
You can find an explanation for the example here with tutorial examples:
Sample Proxy Template Design-tutorialspoint.com
Look below articles
source to share