I was considering using a Singleton pattern in a winforms application that I am working on, but a lot of people seem to think that singletons are evil. I was planning on making a “Main Menu” form which is a singleton. I can’t think of any reason that I would want multiple instances of my Main Menu, and it is always going to be the first form that comes up, so I am not concerned with wasting resources if it gets instantiated unnecessarily.
Also, I could see issues arising if there are multiple instances of the Main Menu. For example, if another form has a “Main Menu” button and there are multiple instances of the Main Menu, then the decision of which instance to show seems ambiguous.
Also, if I have another winform which has to look at the state of the program to determine whether there is already an instance of the main menu, then I feel like I am breaking modularity, though I might be wrong.
Should I be avoiding the use of a singleton in this case or would it be better to make the Main Menu static?
I just started using c# a couple days ago, and I haven’t really done much with OOP in the last few years, so I apologize if this is a stupid question.
Thanks
Is
MainMenushown all the time? If not, it would make sense to release the old instance when it’s closed and create a new one every time you need to open it. This way other modules won’t need to know of its instances, they’ll just create one when they need to open it.