Singleton is the simplest design pattern which has categorized under creational design patterns.Most significant difference of the Singleton design pattern is allowing application to create only one instance from start to the end of the application.Singleton manage a global instance that can be access by other instances.
Assume we have a system that can manage online users.In there, system is counting user login events and user logout events.This is like a log file.The whole system needs only one log file and it is maintaining accurate user count.
Here a sample class file created for above scenario.Refer this code and try to understand the behavior of singleton pattern.
--source code can be not loaded because of network issues--
Assume we have a system that can manage online users.In there, system is counting user login events and user logout events.This is like a log file.The whole system needs only one log file and it is maintaining accurate user count.
Here a sample class file created for above scenario.Refer this code and try to understand the behavior of singleton pattern.
--source code can be not loaded because of network issues--