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 2 of 11.
Rajeesh said:
1 decade ago
Singleton class is useful in real time application. Take the example of a real time application of Hospital administration system. Whenever you register in the Hospital database, your object is created and you will be provided with a unique number. This ID is only refers to you created only once in lifetime. Just imagine that you are going to a Hospital first time and to see a Physician. Then you are registering your name in the database only once. Next time, if you plan to visit a Cardiologist in the same hospital. Do you think that your ID needs to be created again? Not all right. Because you have already registered before there is no need to create another object again.
Here comes the singleton class concept. We can create only instance that serves the purpose in every time.
Hope you understand the concept well.
Here comes the singleton class concept. We can create only instance that serves the purpose in every time.
Hope you understand the concept well.
(1)
Deep said:
1 decade ago
A class whose number of instances that can be instantiated is limited to one is called a singleton class. Thus, at any given time only one instance can exist, no more.
The singleton design pattern is used whenever the design requires only one instance of a class. Some examples:.
Application classes. There should only be one application class. (Note: Please bear in mind, MFC class 'CWinApp' is not implemented as a singleton class).
Logger classes. For logging purposes of an application there is usually one logger instance required.
The singleton design pattern is used whenever the design requires only one instance of a class. Some examples:.
Application classes. There should only be one application class. (Note: Please bear in mind, MFC class 'CWinApp' is not implemented as a singleton class).
Logger classes. For logging purposes of an application there is usually one logger instance required.
Prem Survase said:
1 decade ago
I can't understand properly concept of Singleton class. ?
Padmanaban said:
1 decade ago
I can't get your definition. Can you make me understand easier?
Pankaj said:
1 decade ago
Tell me also what is singleton class?
Rakesh Sharma said:
1 decade ago
Write the use of singleton class in a program in easy to understand language.
Sneha said:
1 decade ago
How to make singleton class?
Rajkiran said:
1 decade ago
A class whose number of instances that can be instantiated is limited to one is called a singleton class. Thus, at any given time only one instance can exist, no more.
Prasanth said:
1 decade ago
Write a simple exemples in Singleton class?
Sanjaya said:
1 decade ago
class A
{
private:
static A* m_objA;
A(){}; //note constructor is private
public:
~A();
A* GetInstance()
{
if(m_objA)
{
return m_objA;
}
else
{
m_objA = new A();
return m_objA;
}
}
};
{
private:
static A* m_objA;
A(){}; //note constructor is private
public:
~A();
A* GetInstance()
{
if(m_objA)
{
return m_objA;
}
else
{
m_objA = new A();
return m_objA;
}
}
};
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers