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 the purpose of '@customvalidator'?

582


Is struts compatible with other java technologies?

533


Define struts?

624


What is the difference between shocks and struts?

502


How you will make available any message resources definitions file to the struts framework environment?

561






What are the various struts tag libraries?

555


What are the reasons for an error message not being displayed while developing struts application?

547


how does request processor relates to action mapping?

494


State the procedure for using forward attribute of link tag’s.

546


What is action class? What are the types of action class?

533


What are different Struts2 tags? How can we use them?

576


What is actioncontext?

553


What kind of mvc is struts 2?

559


What is interceptor? And life cycle methods of interceptor?

576


How can we upload files in Struts2 application?

592