September 2018
Intermediate to advanced
302 pages
7h 17m
English
Singleton is sometimes treated as a global variable. If you attempt to import it from many different places and your use case is just sharing the same instance, you are probably abusing the pattern. This way, you tightly couple different pieces to the exact imported object. It is one of the vital signs of code smell if you use a global variable instead of passing it down.
On top of that, Singleton is very unpredictable in terms of testing. You receive something that is an effect of mutation. It may be a new object, or the object previously created. You may be tempted to use this to synchronize some form of a state. For instance, let's look at the following example:
export default class Singleton ...Read now
Unlock full access