[RESOLVED] MessageBox etc. in a constructor, would you do that?
what do you think, is showing a message box in a constructor of some class a bad practice? (or any other interaction with the user while initializing an object)
win7 x86, VS 2008 & 2010, C++/CLI, C#, .NET 3.5 & 4.0, VB.NET, VBA... WPF is comming
remeber to give feedback you think my response deserves recognition? perhaps you may want to click the Rate this post link/button and add to my reputation
private lessons are not an option so please don't ask for help in private, I won't replay
if you use Opera and you'd like to have the tab-button functionality for the texteditor take a look at my Opera Tab-UserScirpt; and if you know how to stop firefox from jumping to the next control when you hit tab let me know
Re: MessageBox etc. in a constructor, would you do that?
No, I wouldn't recommend doing that. Your object is then tightly coupled to your GUI. If you want user interaction to decide whether or not a task should take place, you should do that before constructing your object.
NOTE: My code snippets are just snippets. They demonstrate an idea which can be adapted by you to solve your problem. They are not 100% complete and fully functional solutions equipped with error handling.
Re: MessageBox etc. in a constructor, would you do that?
Originally Posted by boudino
Shortlly: No, it isn't.
Are you saying that it is not bad practice to show a messagebox from a class constructor? Going to have to disagree with you there. The UI layer should be responsible for the UI, otherwise you have this tangled mess of code and, when inevitably more than one messagebox is popping up because of some error, you have to start digging through class files to find them and get rid of them. Poor, poor design.
Re: MessageBox etc. in a constructor, would you do that?
Damned! I've anwer another question... I definitely want to say that I consider it is bad practice to show message box in a constructor. Thanks for your notice.
Re: MessageBox etc. in a constructor, would you do that?
ok, you've convinced me not to do it
win7 x86, VS 2008 & 2010, C++/CLI, C#, .NET 3.5 & 4.0, VB.NET, VBA... WPF is comming
remeber to give feedback you think my response deserves recognition? perhaps you may want to click the Rate this post link/button and add to my reputation
private lessons are not an option so please don't ask for help in private, I won't replay
if you use Opera and you'd like to have the tab-button functionality for the texteditor take a look at my Opera Tab-UserScirpt; and if you know how to stop firefox from jumping to the next control when you hit tab let me know
Bookmarks