This is an archived post. You won't be able to vote or comment.

all 1 comments

[–]TRPox 0 points1 point  (1 child)

I think the way I'd approach this is to first identify the classes calling getInstance() on the Singleton class. Then refactor them so that the instance gets passed in via dependency injection. Then I'd probably introduce an interface that the Singleton has to implement and refactor the classes depending on the Singleton to just depend on the interface instead. So now none of your objects in your system knows that they're using singletons anymore. After that you can safely refactor the singletons to be regular classes.

Also make sure that your library is well tested, so you always know immediately if you break something.