A
Atul Malaviya
From a design/usability perspective.
When will one use a singleton pattern and when a class with purely
static members?
What are the pros and cons? I have inherited a code base which is full
of both these and I am a bit confused on this count.
Singleton insures one object of a class in the application. A class
with purely static members and a private constructor also strives to
achieve the same.
The only difference I can think of is that in the second case we are
not creating an object so we are saving some memory space. Which,in my
opinion is not a decent enough reason to decide against one of the
options.
Where will we use one and not the other? Any inputs/insights will be
appreciated.
When will one use a singleton pattern and when a class with purely
static members?
What are the pros and cons? I have inherited a code base which is full
of both these and I am a bit confused on this count.
Singleton insures one object of a class in the application. A class
with purely static members and a private constructor also strives to
achieve the same.
The only difference I can think of is that in the second case we are
not creating an object so we are saving some memory space. Which,in my
opinion is not a decent enough reason to decide against one of the
options.
Where will we use one and not the other? Any inputs/insights will be
appreciated.