Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should a user interface be implemented using the Singleton design pattern?

I can't think of many reasons (or any at all) in which multiple independent user interfaces should be instantiated in a desktop application. Is it good practice to implement the UI as a singleton? Are there are advantages or disadvantages to this approach?

like image 749
Martin Doms Avatar asked Mar 02 '23 05:03

Martin Doms


2 Answers

uh...i open multiple copies of Internet Explorer, Word, and Excel all the time!

EDIT: I also have several emails open at once in Eudora

I see no good reason to restrict a user-interface to a singleton...

like image 83
Steven A. Lowe Avatar answered Apr 28 '23 08:04

Steven A. Lowe


I can think of a couple:

1) Document interfaces. If your application deals with documents, it's better to let each one have its own window. It makes it easier for the user to arrange their workspace and switch between documents using the OS's app switching capabilities. A lot of MDI applications prevent this by corraling multiple documents into the same window, which limits usability of screen real estate in a multiple monitor scenario.

2) Views. It's often the case that several different views on the data behind your UI cannot be easily combined in a single UI instance. You can't always predict what combinations of data your user will want to see at the same time, so it's better to give them the flexibility to instantiate multiple UIs.

As an aside, it's worth noting that many people consider Singleton an anti-pattern.

like image 45
jonsequitur Avatar answered Apr 28 '23 08:04

jonsequitur