I’m currently developing an application in which I’m using a plugin system. For providing unified access to a configuration screen I added a settings class to each plugin which must implement a settings interface. Furthermore each Settings class should implement the singleton pattern as shown below:
public sealed class PluginSettings : IPluginSettings
{
private static readonly PluginSettings instance = new PluginSettings();
private PluginSettings () { }
public static PluginSettings Instance
{
get
{
return instance;
}
}
# region interface implementation
# ...
# endregion
}
Is it possible to implement the singleton pattern already in the interface?
Any help appreciated – thanks in advance!
You could optionally use an abstract class instead of an interface and implement the singleton in the base abstract class.
You can use generics to make the singleton instance of the type of the inheriting class.