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


Please Help Members By Posting Answers For Below Questions

What is size () in java?

540


When should the method invokelater() be used?

578


What are the 8 data types in java?

517


Explain about sets?

565


What is the importance of main method in Java?

570






What causes memory leaks in java?

488


Explain java coding standards for classes or java coding conventions for classes?

610


What is the preferred size of a component in java programming?

535


What is an inner class in java?

520


State the merge-sort principle and its time complexity.

567


What is 16 bits called?

493


What is split return?

488


What is the difference between static and non-static variables in java programming?

515


What is boolean used for?

585


What is widening and narrowing in java? Discuss with an example.

554