As I go through the differences between Singleton Vs Static class, I came across one point that we can inherit an interface in singleton class and can call singleton through interface for multiple implementation.
What exactly mean we can call singleton through interface for multiple implementation, please suggest some code demonstration with some good real time example.
Here I m also using logging through below, but what exactly mean for multiple implementation?
class Program { static void Main(string[] args) { ILogger logger = Logger.GetLogger(); logger.LogMessage("Hello"); } } public interface ILogger { void LogMessage(string message); } public class Logger : ILogger { private static Logger instance; public static Logger GetLogger() { return instance ?? (instance = new Logger()); } public void LogMessage(string message) { Console.WriteLine(message); } }