3 ms·
So, as per the argument in the submission, you should create a function that manages that. And then you want to make sure the class is not instantiated other th
by Etherlord87 5y ago
So, as per the argument in the submission, you should create a function that manages that. And then you want to make sure the class is not instantiated other than with that function. So you recreate a singleton, but one of the methods is outside the class, is harder to find, easier to forget about when moving code around etc.
Yes, making sure no one makes more than one instance of the class is defensive programming and you could consider it bad, but a lot of techniques in programming are defensive like that, especially in OOP.