I know, we already discussed this on different coderanch topic but i am still not convince!
Hence i am putting my question one again, in detail mode.
Lets say we have situation to implement a service class
Now it is clear that this service class is fully stateless.
Now their is different approach to access/design this class.
Way 1: Create a new instance every time
So people who hate static stuffs in their application, they create the instance of this class every time.
which could be the first way.
Way 2: Use static methods
When we look on the all stateless class in JDK,
String, Integer, Collections, etc
All use static methods in them, which is a nice way, since their is no state to maintain then why to create instance every time.
use static methods as JDK do.
Way 3: Using singleton class very much like Spring do
Now this sound bit strange but this what we are doing now days in most of the web application as Spring is the most widely used
java framework we have in market.
As spring do, it create a single instance of all stateless beans(unless prototype is not enabled)
Note: I know its not like a java singleton pattern, but if you have a single application context file in your application, then it is not different either.
Now way 3 sound more promising as we are not creating instance every time and we are not using static method either.
what we can have is (if we are not using spring !!)
Please share your thoughts.
Lets have discussion on following aspects
1. Performance.
2. How easy it is to use.
3. Maintainability.