Everytime I make a http request I must make sure there is internet connection.
public class InternetCheck {
public static boolean isOnline() {
}
}
class Httphandler {
public static String login(String uname,String pass){
if(InternetCkeck.isOnline)//make the request
}
}
What if I add logout,delete,uploadFile?I have to copy the if line again and so on for every http I make.
I was looking at the proxy pattern but I don't thing is the right choice.Using the proxy pattern every time I add a new request I also have to add to the proxy.(Maybe this is acceptable?)
(Maybe I get proxy pattern wrong that's why i'm gone explain how I undertand it: Make an interface with some methods: for eg login.Then create two classes one proxy one and the real thing. Then in the proxy I make the method login where I do put the if and if is true I call the method from the real thing. But again everytime I do add a new http call I have now to add it in two classes.How is this better than simply copy pasting the if statement alone?)
How to do this in a nice way without the copy paste thing?(I'm thinking about dry)