how to implement singletun design patteren in struts?

Answer Posted / sk neelofar

public class Sample
{
pubic static Sample s=new Sample();
private sample(){
}//constructor
public static smple getInstance()//static factory method
{
return s;
}//method
}//class

......
Sample s1= Sample.getInstance();
Sample s2= Sample.getInstance();


1.A static method can b called outside the class using clas
name.
2.In this implementation, we used private constructor n a
static factory method to make a class as a singleton class.
3.if we call the getInstance(); of the class for any no. of
times, same object of the class will b returned to the
programmer.
4. the programmer can't create an object pf this class
outside the class, coz it has a private constructor.

Is This Answer Correct ?    23 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is Struts2?

809


What is action servlet in struts?

700


What is the difference between session scope and request scope when saving formbean ?

747


What is the apache struts vulnerability?

697


What is the purpose of global-forwards tag in struct-config.xml?

754


How to use dispatchaction?

760


Describe the two types of formbeans.

757


1.can we transfer a request from one struts application to another struts application? 2. how many types of action servlets r there what r they

2944


What is interceptor struts2?

724


What is the difference between Jakarta Struts and Apache Struts? Which one is better to use?

766


How the exceptions are handled in struts?

730


What do you mean by a custom tag?

720


How to convert struts to spring mvc?

725


How to work with error tags?

743


In which order struts framework searches for a message bundle?

720