The 'singleton-ness' of a class is an important aspect of how a class should be used. However, it usually doesn't have any explicit status in the exposed API of a class. Yes, conventional method names such as getInstance() are often used, but that's not exactly what I'm referring to here.
A 'tag interface' is an interface which contains no methods or data. An example of a tag interface is Serializable.
Would it not be useful to define a tag interface for singletons? This would:
- allow them to be easily identified in the code base of a project
- be more explicit
- provide a place to document how singletons should be treated. As one example, one could mention that long-lived objects are fruitful sources of memory leaks, and that singletons should never be wired to short-lived objects.
This is a simple idea, but I have never seen it mentioned anywhere.