i have a class that (right now) is static:
public static class Grob
{
public static void Frob()
{
Foo.Bar();
}
}
And that works well. Code calls:
Grob.Frob();
and all is right with the world. Now i want my class to implement an interface:
public static class Grob : IOldNewGrob
{
public static void Frob()
{
Foo.Bar();
}
}
Unfortunately that does not work, because reasons.
So i would try changing to class to a singleton:
public sealed class Grob
{
private static volatile Singleton instance;
private static object syncRoot = new Object();
private Grob() {}
public static Singleton Instance
{
get
{
if (instance == null)
{
lock (syncRoot)
{
if (instance == null)
instance = new Singleton();
}
}
return instance;
}
}
}
Which works well enough, except that it doesn't work - the code no longer compiles:
Grob.Frob();
In other languages it would not be a problem. i would create a global Grob
function (called Grob
because that's the name that existing code needs):
function Grob(): GrobSingleton;
{
return Grob.Instance;
}
//and rename Grob class to something else
public sealed class GrobSinglton
{
...
}
except that C# doesn't have global functions.
In the end:
- i don't need a global function
- i don't need a static class to be able to implement an interface
- i don't need a singleton
i just want it all to work.