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?
Answer Posted / 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 |
Post New Answer View All Answers
What is scope of a variable?
What is a void method?
What does it mean to be immutable?
Explain inner classes ?
How do I convert a string to an int in java?
How many types of threads are there in java?
Explain about main() method in java ?
How to instantiate static nested classes in java?
hi am an engineering student and my next plan is for ms in either in us or australia i got my passport but i dont know anything bout visa can u give brief idea 1)How to get prepared for visa and 2)How to apply for top universities and 3)How to pay the fee and so on These all are basic questions plz give me a clear idea
What are keywords in programming?
How do you allocate memory to object?
What are desktop procedures?
What is the difference between serializable and externalizable interface?
What is a consumer in java?
What happens if a constructor is declared private?