代码改变世界

单件,让类就一个实例

2008-01-23 17:12  cppguy  阅读(413)  评论(0编辑  收藏  举报

//单件类
public class SingleTonHolder<T> where T : new()
{
    private static T instance;
    private static bool destory; //用户管理永生件       
    private static bool disposed = false;
    public static bool Disposed
    {
        get
        {
            return disposed;
        }
        set
        {
            disposed = value;
        }
    }
    public static T Instance()
    {
        if (instance == null || disposed == true)
        {

            if (destory)
            {

            }
            instance = new T();
        }
        return instance;
    }
}
//泛型对象工厂