Skip to content

Instantly share code, notes, and snippets.

@yemrekeskin
Last active December 15, 2015 09:39
Show Gist options
  • Save yemrekeskin/5240378 to your computer and use it in GitHub Desktop.
Save yemrekeskin/5240378 to your computer and use it in GitHub Desktop.
Multiton Design pattern
namespace Multiton.Pattern
{
public sealed class Sample
{
static Dictionary<string, Sample> _instances = new Dictionary<string, Sample>();
// the key type of dictionary collection can be int,string etc.
static object _lock = new object();
private Sample()
{
// private ctor
}
public static Sample GetSample(string key)
{
lock (_lock)
{
if (!_instances.ContainsKey(key))
_instances.Add(key, new Sample());
}
return _instances[key];
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment