ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
tip   To Refer this Site to Your Friends   Click Here
Google
 
Categories  >>  Software  >>  Software Design  >>  Design Patterns
 
 


 

 
 Design Patterns interview questions  Design Patterns Interview Questions
 UML interview questions  UML Interview Questions
 OOAD interview questions  OOAD Interview Questions
 Software Design Tools interview questions  Software Design Tools Interview Questions
 Requirements Management interview questions  Requirements Management Interview Questions
 Project Planning interview questions  Project Planning Interview Questions
 Project Management interview questions  Project Management Interview Questions
 Technical Writer interview questions  Technical Writer Interview Questions
 Software Design AllOther interview questions  Software Design AllOther Interview Questions
Question
What is singleton design pattern
 Question Submitted By :: Kiran
I also faced this Question!!     Rank Answer Posted By  
 
  Re: What is singleton design pattern
Answer
# 1
Singleton design pattern is a a creational pattern to 
dictate how and when objects get created and it's main 
purpose is to ensure that a class has only one instance

Example:
#define NULL 0

class Singleton
{
private:
	Singleton(Singleton&){}
	Singleton& operator =(Singleton&);
	int nValue;
	static Singleton* pSingleton;
	Singleton():nValue(10)
	{
	}
public:
	static Singleton*Instance()
	{

		if(NULL == pSingleton)
		{
			pSingleton = new Singleton();
		}
		return pSingleton;
	}
	void setValue(int val)
	{
		nValue = val;
	}
	int getValue()
	{
		return nValue;
	}
};
Singleton* Singleton::pSingleton = NULL;

int main(int argc, char* argv[])
{
	Singleton *abc = NULL;
	cout<<Singleton::Instance()->getValue()<<endl;
	Singleton::Instance()->setValue(20);

	Singleton *xyz = NULL;
	cout<<xyz->Instance()->getValue()<<endl;
	Singleton *sss = Singleton::Instance();
	return 0;
}
 
Is This Answer Correct ?    13 Yes 4 No
Lokesh
 

 
 
 
Other Design Patterns Interview Questions
 
  Question Asked @ Answers
 
What is grouping in CSS?  1
What is 'good design'?  2
What are actually Model,view,Controller in MVC Pattern? Honeywell2
What is software 'quality'?  2
In which application lifecycle phases is an application architecture produced?  1
what is cascading order?  1
What is impedance mismatch and How to solve the problem? HP1
How do you ensure quality of code ? Infosys2
what are design patterns..?what design patterns used in .net.  1
How might prototyping be used as part of the SDLC?  3
What is ESD?  1
Can any one suggest me the best institute for Software Design , Design Patterns and architecture in Hyderabad please. Thanks in Advance. IBM2
write 5 best test cases like any password?password should be mixed case with atlest one number or special characters? Wipro1
What are cascaded style sheets?  1
What is the publish/subscribe model?  1
what is design patterns? which design patterns mostly used in .net? How it is used with examples? Satyam1
If i make my selection in State Dropdown list, i would the City and ZipCode dropdown list to be automatically reupdated based on the State i select.(This to avoid the user select a City or Zipcode that does not correspond to the State previously selected.)  1
Which Design Patterns you know? Honeywell4
Explain the singleton, facade, or handle class design pattern? ABC1
Explain Internal Style Sheets?  1
 
For more Design Patterns Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com