请考虑以下代码
public sealed class Singleton
{
private static readonly Singleton instance = new Singleton();
public static Singleton Instance { get { return instance; } }
static Singleton() {}
private Singleton() {}
}
Run Code Online (Sandbox Code Playgroud)
题
1)这里静态构造函数的目的是什么?(我知道在创建类的第一个实例之前将调用静态构造函数).但是在上面代码的上下文中我不能在没有静态构造函数的情况下使用它吗?
2)我听说单身人士的一个优点是它可以延伸到工厂.既然它是一个密封的类,你将如何将它扩展到工厂?你能举一些例子吗?