This article is not intended to be a restatement of those. Instead I want to describe a solution to a problem that occurred to me soon after reading Microsoft's recommended implementation of the Singleton pattern in .NET.
Read full article from Incorporating Parameterized Construction in the Singleton Design Pattern - CodeProject
sealed class WebMaster
{
public static readonly WebMaster Instance = new WebMaster();
public WebMaster Create(string firstName, string lastName)
{
_firstName = firstName;
_lastName = lastName;
return Instance;
}
WebMaster webMaster = WebMaster.Instance.Create("Kevin", "McFarlane");
If we wish to prevent multiple initialization through calling
Create more than once we can just add an internal flag to indicate whether the instance has been "created" or not and raise an exception if it has.
No comments:
Post a Comment