🏗️Singleton Pattern
Also known as Singleton
Only one object of a class may exist. Every part shares it.
Think of it like
Think of it like the one school bell. Every class hears the same bell, and there is never a second one.
Example
Jack's app reads its settings file once into a Config singleton. Every part asks Config for values. The file is never read twice.
Why it matters
Some things really should exist only once. The pattern stops two copies from drifting apart.
Definition
Common mistake
Key takeaways
- 1Only one. Never a second object.
- 2Reach it anywhere. One shared access point.
- 3Hidden global. Use with care.