Sure, we’ve all heard of Singleton, the design pattern that limits the number of instances of a class to one. It’s a feel good pattern because it’s easy to use and make us feel smarter in front of our co-workers, even though some would argue that Singletons are just glorified global variables. But for a long time, I have wondered if it would be possible to use the same idea to limit the number of instances to two or more instead of just one. I called this hypothetical pattern an “N-gleton”, pronounced “en-gull-ton”. (UPDATE: Comments from readers inform me that this is called a “Multiton“) It may not be possible to make a poly-instance singleton, it may not be good programming practices, I’m not even sure I can think of a reason why it might be useful, but today, I tried my hand at inventing it and found something else entirely.
