lundi 16 octobre 2017

How to implement a subclassable Singleton in Java

I am looking for a way to implement an abstract class (or effectively abstract) that enforces only one instance of each subclass.

I am fairly sure this would be pretty simple to implement with a Factory but I would be interested to know if it can be done without knowing all subclass types, i.e a generic singleton enforcer class.

Right now I am mostly just playing around with the idea for something like this, So I am not looking for feedback that questions the design choice here.

The language I am working in is Java, but right now I am not necessarily worried about implementation details, Unless it is not possible in Java, then, of course, provide evidence that it is not possible.

Aucun commentaire:

Enregistrer un commentaire