So basically if a device has internet, certain actions are allowed to happen and if there is no internet then certain actions aren't allow to run.
online mode & offline mode.
What are some ways to construct this type of situation, what are some patterns to use?
The obvious one that comes to mind is a flag as the condition and an if else statement to handle the code choice.
online = true
getconnection()
if {!getconnection){
online = false
}
if (online) {
do everything online
}else {
do only offline stuff
}
What if there's already an existing base of code that needs this logic factored in, what's an optimal remedy for that situation?
Maybe this code will help: