Singleton pattern ਇਹ ਯਕੀਨੀ ਬਣਾਉਂਦਾ ਹੈ ਕਿ ਇੱਕ ਕਲਾਸ ਦਾ ਸਿਰਫ ਇੱਕ ਹੀ ਨਿਰਮਾਣ ਹੋ ਅਤੇ ਇਹ ਇਸ ਤੱਕ ਪਹੁੰਚ ਦਾ ਇੱਕ ਗਲੋਬਲ ਬਿੰਦੂ ਪ੍ਰਦਾਨ ਕਰੇ। ਇਸ ਦੀ ਵਰਤੋਂ ਉਦੋਂ ਕੀਤੀ ਜਾਂਦੀ ਹੈ ਜਦੋਂ ਠੀਕ ਇੱਕ ਅਬਜੈਕਟ ਕਿਸੇ ਚੀਜ਼ ਨੂੰ ਤਾਲਮੇਲ ਕਰਨਾ ਚਾਹੀਦਾ ਹੋ (ਕਨਫਿਗਰੇਸ਼ਨ, ਕਨੈਕਸ਼ਨ ਪੂਲ, ਇੱਕ logger), ਹਾਲਾਂਕਿ ਇਹ ਕੁਝ ਵਿਵਾਦਾਸਪਦ ਵੀ ਹੈ।
Singleton ਕੀ ਕਰਦਾ ਹੈ
SINGLETON → guarantee a class has only ONE instance, with global access to it:
→ the class controls its own instantiation (private constructor)
→ returns the SAME instance every time it's requested
→ for: things there should only be ONE of, accessed from many places
