Last post Feb 08, 2016 09:25 AM by gerryLowry
Feb 08, 2016 06:53 AM|Shibly|LINK
I want to create a class which instance can allocated only once at a time. Is there any way to do this.
Thanks in advance.
Feb 08, 2016 07:52 AM|sam_xiii|LINK
You want to look at the
http://www.sambeauvois.be | @sambeauvois
Feb 08, 2016 09:25 AM|gerrylowry|LINK
You need imho to clarify your question:
I want to create a class which instance can allocated only once at a time.
What do you mean by "only once at a time"?
The purpose of the Singleton pattern is to ensure that there is only one instance of a class, and that there is a global access point to that object. The pattern ensures
that the class is instantiated only once and that all requests are directed to that one and only object. Moreover, the object should not be created until it is actually needed. In the Singleton pattern, it is the class itself that
is responsible for ensuring this constraint, not the clients of the class.
if the above is what you mean by "only once at a time", then you can achieve your goal by using the Singleton pattern.
see the answer by sam_xiii above for links regarding the Singleton pattern.
https://msdn.microsoft.com/en-us/library/ee817670.aspx "Exploring the Singleton Design Pattern"
https://msdn.microsoft.com/en-us/library/ff650316.aspx "Implementing Singleton in C#"
study the above articles. you can find many more articles if you search on singleton
OTOH, if you mean something else by "only once at a time", then please provide more details.