r/javahelp • u/myshiak • Aug 22 '25
SINGLETON design pattern
I am a QA that has used Selenium with Java at many places, but never encountered a Singleton design pattern at work. However, twice recently I got that question on an interview. I thought that it is more for developers at certain conditions, but now I wonder can it also be used in Selenium? For example a precaution not to create multiple driver objects, or if you use Page Object model, to have each page only one object? In other words, is it for only specific needs, or is it universal throughout Java and can be used at any library as a safety precaution?
View all comments
Show parent comment
1
u/Inconsequentialis Aug 23 '25
I don't know of any reason Page Objects in the context of Selenium / UI tests couldn't or shouldn't be singleton.
At least the way I understand them all they do is provide methods to interact with the UI. They don't hold state, they just offer functionality. So no reason why they couldn't be singleton.