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

Why actionservlet is singleton in struts?

670


What do you mean by inner class and anonymous class?

680


What is the purpose of @after?

663


What is the use of lookupdispatchaction?

647


How an actionform bean is created?

654






What is difference between spring and struts?

595


What are action errors?

646


Where can I get help with struts?

655


What are the various struts tag libraries?

631


How client side validation is enabled on a jsp form?

669


What is s token?

617


What is the purpose of @beforeresult annotation?

664


What is the purpose of @urlvalidator annotation?

633


What are the components of struts framework?

667


What are the sections into which a strut configuration file can be divided?

650