在继承中子类自动实现单例模式

@Paradox 技术支持

1
2
3
4
5
6
7
8
9
10
11
12
13
public abstract class Base<T> where T : new()
{
    private static T _instance;
    public static T Instance
    {
        get
        {
            if (_instance == null)
                _instance = new T();
            return _instance;
        }
    }
}
1
2
3
public sealed class A : Base<A>
{
}

更多内容:http://www.liubaicai.net/index.php/archives/366

 

posted @ 2014-11-14 14:30  刘白菜  阅读(1447)  评论(1编辑  收藏  举报