DEV Community

[Comment from a deleted post]
 
chrisvasqm profile image
Christian Vasquez • Edited

Thanks for the tips Scott,

Regarding the Singleton:

"and if you're mutating state in a singleton, in Kotlin or Java, you're doing it wrong."

Could you make an example with a real life scenario?

I had the idea that config files or something like a ShoppingCart as a Singleton is OK.

So taking the ShoppingCart as an example, I guess it would have a List<Product> products property that allows users to add() and remove() products from it. What could be an alternative?