Singleton Design Pattern
1. Class in sealed (sealed will prevent the class inheritances(even if child child is nested class))
2. Constructor is private (helps in preventing any external instantiations of objects)
3. Double check - inner check so as to create instance. Outer check so as to not check if object is created again and again.
4. Lock so as disallow parallel invoke
Thread Safe version
1. Class in sealed (sealed will prevent the class inheritances(even if child child is nested class))
2. Constructor is private (helps in preventing any external instantiations of objects)
3. Double check - inner check so as to create instance. Outer check so as to not check if object is created again and again.
4. Lock so as disallow parallel invoke
Thread Safe version
No comments:
Post a Comment