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
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 |
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 |
how many ways to create Thread and which one is good? runnable interface ot Thread class?
Program to find greatest prime number in n numbers?
I have a Arraylist object, it has duplecate values also. Now question is i want delete duplecate data in that objet with out using Set?
What are autoboxing and unboxing? When does it occur?
What is parsing a sentence?
can we overload main method?
Write a program to show whether a graph is a tree or not using adjacency matrix.
What is %02d?
How do I find and replace in word?
What is the difference between the paint() and repaint() methods in java programming?
Name the runtime exceptions that occurs frequently?
Why heap memory is called heap?