Singleton Design Pattern Example Step by Step using Swift
Content:
- Why We need Singleton
- Simple Singleton Example
- Multi Thread Singleton Problem
- Thread Safe Singleton Example
When discussing things like patterns and architecture, it's easy to fall into the trap of being a bit too theoretical. While it's nice to have our code be theoretically "correct" and to follow all the best practices and principles - reality often hits and we need to find some sort of middle ground.
So what concrete problems are singletons usually causing, and why should they be avoided? The three main reasons why I tend to avoid singletons are: