This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I have a DAO class which is spring managed. I need to decide whether to use static/non-static methods. I believe using non-static methods will force callers of the DAO to wait until it is fully initialised, and is the better option, since you have a fully formed class. please let me know what are the factors that I must consider before deciding?
Why do you want a singleton in the first place?
You should be initialising the object via its constructor, without letting a “this reference” escape, Then nobody can get anywhere near the object until it is fully initialised. In which case you would probably not want static fields.
I am sure other people will have different opinions.
Since that's a DAO managed by Spring container, you don't need to worry about partially initialized object. Spring instantiates and initializes all the beans on startup (there are of course way of doing lazy-initialization), but that doesn't make any difference, because in that case also, Spring will ensure you don't get partially initialized object. So, you should not add static method, not for at least this purpose.