I would create:
A
Command
class that represent an action to perform (interaction with the server). Store in this object information such asendpointUrl
,httpMethod
,parameters
and anything else you need to perform a call to the server. Make this class serializable.An
Executor
class that, given aCommand
, can perform the action (calling server endpoint with correct parameters and everything).
When the Executor
received a command that cannot be executed because the server is down it serialize this command. It needs to be on a permanent storage (not in memory) for the case the application is stopped with pending commands.
When the application start you should add logic to deserialize all commands and execute them. You can also implement a listener on network state, when connectivity is back do the same thing as startup: deserialize commands and execute them.