• Post Reply Bookmark Topic Watch Topic
  • New Topic

Error Display

 
John Chien
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
For the GUI design, I found that it is necessary to show some error messages to the user. This may happen in different components of the GUI. I do not want to implement them in each class. What I am thinking is to design a class called MessageDisplay to display the messages.
I am thinking in designing this class to be a Singleton. Is it a correct approach ?
Thanks,
John Chien
 
Miguel Roque
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello.
Why not a class with a static method that shows the error message?
Miguel
 
Mark Spritzler
ranger
Sheriff
Posts: 17309
11
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes this is an approach that is good to use, as it handles all Exceptions that the client needs to display. Now as a Singleton and in a seperate class I am not positive if that is good or bad.
Actually I just added two lines to my main class. in the public static void main() method.

This code was in the catch of the main try statements. So I make sure that all the exceptions that can occur in the client, that the client must show, gets thrown all the way up to display this message.
So I didn't need to create a different class at all.
But like in everything, you get to choose your approach.
Mark
 
John Smith
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Why not a class with a static method that shows the error message?

That's what I did, too:

Eugene.
 
Mark Spritzler
ranger
Sheriff
Posts: 17309
11
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's cool Eugene, in that case I would suggest a class like yours. In mine I only had the error messages, so having one catch was fine in my code, but if I was to make it show more types of messages then refactoring like yours would be better.
Mark
 
John Chien
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cool.
Yes, I should design class with static methods.
Singleton is NOT the way to go.
Eugene, Thank you for the code.
John Chien
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!