KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I realize there is much discussion about singletons and why that are bad. That is not what this question is about. I understand the drawbacks to singletons. I have a scenario where using a singleton is easy and appears to make sense. However, I want an alternative that will accomplish what I need without a lot of overhead. Our application is designed as a client that typically runs on laptops in the field and communicates with a back end server. We have a status bar at the bottom of the main application. It contains a few text areas that show various statues and information as well as several icons. The icons change their image to indicate their state. Such as a GPS icon that indicates if it is connected or not as well as error state. Our main class is called MobileMain. It owns the status bar area and is responsible for creating it. We then have a StatusBarManager class. The StatusBarManager is currently a static class, but could also be a singleton. Here is the start of the class. public static class StatusBarManager { static ScreenStatusBar StatusBar; /// <summary> /// Creates the status bar that it manages and returns it. /// </summary> public static ScreenStatusBar CreateStatusBar() { StatusBar = new ScreenStatusBar(); return StatusBar; } The MobileMain asks the StatusBarManager for a StatusBar. It then uses the StatusBar. No other classes see the StatusBar, just the StatusBarManager. Updates to the status bar can come from pretty much anywhere in the application. There are around 20 classes that can update the text areas on the status bar and additional classes that update the icon states. There will only every be one StatusBar and one StatusBarManager. Any suggestions for a better implemention? Some thoughts that I had: Make the StatusBarManager an instance class. In my MobileMain class ho
Tags (comma-separated)
Save Edits
Cancel