Skip to content

Instantly share code, notes, and snippets.

@thedeemon
Created September 24, 2019 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thedeemon/e743410393045ad242465ec9b24c4023 to your computer and use it in GitHub Desktop.
Save thedeemon/e743410393045ad242465ec9b24c4023 to your computer and use it in GitHub Desktop.
ILogger {
void log(string msg);
}
class BoringLogger : ILogger {
overrride void log(string msg) {...}
}
class ColorfulLogger : ILogger {
overrride void log(string msg) {...}
}
void writef(T...)(ILogger logger, T params) {
// all generic code of turning different types of params to string
// then pass this string to logger
}
main() {
auto logger1 = new BoringLogger;
auto logger2 = new ColorfulLogger;
logger1.writef(1, "hi", 3.3);
logger2.writef(1, "hi", 3.3);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment