Last active
December 15, 2015 09:39
-
-
Save yemrekeskin/5240378 to your computer and use it in GitHub Desktop.
Multiton Design pattern
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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