4 ms·
> There are cases where you only have 1 instance of something, never 2 or more. I've seen plenty of cases where this assumption stops being true and only throu
by estebank 6y ago
> There are cases where you only have 1 instance of something, never 2 or more.
I've seen plenty of cases where this assumption stops being true and only through pain and sweat the design could be disentangled after the fact. On the other hand I've never been more than mildly inconvenienced by in practice global state that had an API that didn't assume it.
Writing the logic as if it could be more than one at a time also makes it much easier to write isolated tests and reduced integration tests.
I have always seen singleton designs in codebases where testing was wanting.
- simion314 6y agoAs I said it depends, do you pass in js the Math object around because you assume that in future you want to replace the Math.abs function with something different ? Sure I seen the issues you mentioned too and many other issues where the initial requirements or assumptions changed.