"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?
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Thanks for the tips Scott,
Regarding the Singleton:
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 toadd()
andremove()
products from it. What could be an alternative?