三个要点:
- 是某个类只能有一个实例;
- 是它必须自行创建这个实例;
- 是它必须自行向整个系统提供这个实例;
public class CompanyBF
{
/// <summary>
/// 声明对象(唯一)
/// </summary>
private static CompanyBF _userBookInfoM;
/// <summary>
/// 初始化object新实例
/// </summary>
private static object _object = new object();
public static CompanyBF getInstance()
{
if (_userBookInfoM == null)
{
lock (_object)
{
if (_userBookInfoM == null)
{
_userBookInfoM = new CompanyBF();
}
}
}
return _userBookInfoM;
}
}