i am writing an application for android but i am planning to build this for the pc, too. So i want to reuse as much code as possible. But there are some cases where i have to use platform-specific functions. For example for logging-output and loading resources. I am searching for an easy solution to abstract these features. My current solution is that i have written this class
public class LoggerAndroid{
public static void debug(String tag, String msg) {
Log.d(tag, msg);
}
public static void error(String tag, String msg) {
Log.e(tag, msg);
}
public static void info(String tag, String msg) {
Log.i(tag, msg);
}
public static void warn(String tag, String msg) {
Log.w(tag, msg);
}
}
and this one
public class Logger extends LoggerAndroid{
}
In my code i use expressions like
Logger.info("test", "HelloWorld");
and for writing the pc application i write another log class with the same methods and let Logger inherit from that one. So there are very few changes to make and using the log-methods is still easy. But i think maintaining the code and be quite heavy-handed. Are there better solutions for that?