Singletons


#1

Hello all,
I am just thinking did we really need singletons in ImageStore and PossessionStore, or it is just “included” for learning purposes? Suppose there are another ways which bypass singletons?
Joe, by the way, great book! I have both editions, but this second is much better explains key aspects!


#2

Singletons aren’t just a random concept; sometimes you really do want to be sure there is only a single instance of a class. Apple’s docs note that UIApplication and UIAccelerometer are implemented as singletons.

You CAN conceivably say, “I’m the only one who’s ever going to use this, so why go through the effort? I’ll just instantiate it once.” So sure, “bypass” the singleton pattern if you like. But you’d be doing yourself a disservice by not enforcing it in code if you truly only ever want one.