C++ Programming - OOPS Concepts - Discussion
Discussion Forum : OOPS Concepts - General Questions (Q.No. 1)
1.
Which of the following type of class allows only one object of it to be created?
Discussion:
104 comments Page 8 of 11.
Sonu said:
1 decade ago
What is meant by singleton class?
Kamal dhaker said:
1 decade ago
How we create singleton class?
Kiran said:
1 decade ago
So the class derived as private is called singleton class?
Manish singh said:
1 decade ago
When class having only one class is called singleton class;
Means that single=means one it means that required of one object.
Means that single=means one it means that required of one object.
LoveToProgram said:
1 decade ago
A Singleton class is a design pattern, which creates only a single instance at any time.
When is it required:
Based on the requirement.
Example : Singletons are often used to control access to resources such as database connections or sockets.
Suppose u have licence for only one connection for database, A singleton connection obj makes sure that only one connection can be made at any time.
How this can be implemented:
1. Have a static method, creates the instance if the instance does not exists. If the instance already there then returns the reference to the existing obj.
2. Have a private constructor.
Why Static method:
No obj is required to call static method and memory is used only when required.
private constructor is to make sure that object is not created in any other way.
I explained as per my knowledge. Hope this would be useful.
When is it required:
Based on the requirement.
Example : Singletons are often used to control access to resources such as database connections or sockets.
Suppose u have licence for only one connection for database, A singleton connection obj makes sure that only one connection can be made at any time.
How this can be implemented:
1. Have a static method, creates the instance if the instance does not exists. If the instance already there then returns the reference to the existing obj.
2. Have a private constructor.
Why Static method:
No obj is required to call static method and memory is used only when required.
private constructor is to make sure that object is not created in any other way.
I explained as per my knowledge. Hope this would be useful.
Lalit Kumar Soni said:
1 decade ago
I can't understand following statement:
static A* m_objA;
And Also term Singleton & Longer class.
static A* m_objA;
And Also term Singleton & Longer class.
Bibhishan said:
1 decade ago
Singleton class has only one instance this concept given in the design pattern.
Chandrababu said:
1 decade ago
What is the use of singleton class? please give me simple explanation.
Uma said:
1 decade ago
A class which is having only single object is called singleton.
Dattatraya dhokane said:
1 decade ago
Can I get more info about singltone class.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers