Suppose there is an Online shopping cart application having
different objects like Cart, SelectionItem, Billing,
COnfiguration, Authentication, Authorization,
PersonalDetails etc. Out of this which one can be made a
singleton pattern and why?

Answers were Sorted based on User's Feedback



Suppose there is an Online shopping cart application having different objects like Cart, Selection..

Answer / sabir hussain

Singleton ensure that class has only one instance and
provide a global point of access to it.

It can be applied in a situation where your implementation
is independent and utilize resource that should be
initialized once within your application environment.

1) So Configuration can be singleton as we configure
resources that are globally used with your application. (ex:
database connection info.)

2) Authentication and Authorization component can also be
singleton as there implementation are independent and will
not solve any purpose if instantiated twice, if you look in
terms of spring framework all such components are singleton.
Both the component can independently authenticate or
authorize user or user info (validating credit card info).

Cart, SelectionItem and Billing are user specific generally
session scoped, and there can be more then one session per
application, so they cant be Singleton for obvious reason.

Is This Answer Correct ?    16 Yes 2 No

Suppose there is an Online shopping cart application having different objects like Cart, Selection..

Answer / siddharth

With singleton design pattern we can ensure the following:
1) Only one instance on the class is created
2) Provide global point of access to the object.
example: printerspoolers

So in the above question configuration can be made a
singleton design pattern as configuration is same for
everyone

Is This Answer Correct ?    12 Yes 1 No

Post New Answer

More Core Java Interview Questions

What is module in oop?

0 Answers  


What is the difference between an if statement and a switch statement?

0 Answers  


Can Applet have constructors?

5 Answers   Infosys,


What is parseint?

0 Answers  


Draw a UML class diagram for the code fragment given below: public class StringApplet extends Applet { private Label sampleString; private Button showTheString; private ButtonHandler bHandler; private FlowLayout layout; public StringApplet() { sampleString = new Label(" "); showTheString = new Button (" Show the String"); bHandler = new ButtonHandler(); layout = new FlowLayout(); showTheString.addActionListener(bHandler); setLayout(layout); add(sampleString); add(showTheString); } class ButtonHandler implements ActionListener { public void actionPerformed(ActionEvent e) { samplestring.setText("Good Morning"); } } } Note: The methods need not be indicated on the diagram.

0 Answers  


Where will it be used?

0 Answers  


what is mutual exclusion? : Java thread

0 Answers  


There are three interfaces A,B & C. A extends B, B extends C, and C extends A.Is it multiple Inheritance? please anybody help me.....

5 Answers  


Why is multithreading important?

0 Answers  


What are the characteristics of java?

0 Answers  


Tell some latest versions in JAVA related areas?

0 Answers  


What does java final mean?

0 Answers  


Categories