how to implement singletun design patteren in struts?

Answer Posted / shaik baji

Singletun design patteren means we can't create more than
one object for that class which follws Singletun design
pattern.

We can implement it by using one "private" constructor and
one Factory mathod as like follows:

class Sample
{
public static Sample s = new Sample();

private Sample()//constructor
{

}
public static Sample getInstance()//static factory
method
{
return s;
}
}

public class SingleTun
{
public static void main(String arg[])
{
Sample s1= Sample.getInstance();
Sample s2= Sample.getInstance();

}

}

Is This Answer Correct ?    5 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is struts?

729


How to work with error tags?

733


Can a reducer dispatch an action?

689


Which design pattern the interceptors in struts2 is based on?

690


What is difference between interceptors and filters?

722






What is the use of struts config xml file?

641


What is the use of namespace in action mapping in Struts2?

760


What is the purpose of @createifnull annotation annotation?

795


Which file is used by controller to get mapping information for request routing?

757


What are the two types of validations supported by validator framework?

749


What is the purpose of '@customvalidator'?

767


What is the use of Struts.xml configuration file?

689


What is switchaction?

810


When do I need “struts.jar” on my classpath?

720


Provide some important Struts2 constants that you have used?

751