Singleton - GalleryItem


I was wondering… why not store GalleryItems in a singleton as with the CriminalIntent example where Crimes were stored in the Singleton CrimeLab.



It seems like the singleton design pattern would work in this scenario. Not sure why it isn’t applied. Can anyone provide an explanation?


It should work. They probably didn’t implement it to save some typing and stay focused on multithreading. They really covered a lot of ground in this chapter and I had to go over it about three times before I felt like I understood it. One thing that helped me was commenting each method to say which thread it is running in.

Anyway, speaking of multithreading, the singleton pattern they use in the book isn’t thread safe. I don’t think it matters in this app, but it could in others.