CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Oct 2008
    Location
    Cologne, Germany
    Posts
    756

    [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

  2. #2
    Join Date
    Jan 2010
    Posts
    22

    Re: MessageBox etc. in a constructor, would you do that?

    yours becomes jerking and looks ugly right from the start

  3. #3
    Join Date
    May 2007
    Posts
    1,546

    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.
    www.monotorrent.com For all your .NET bittorrent needs

    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.

  4. #4
    Join Date
    Mar 2004
    Location
    Prague, Czech Republic, EU
    Posts
    1,701

    Re: MessageBox etc. in a constructor, would you do that?

    Shortlly: No, it isn't.
    • Make it run.
    • Make it right.
    • Make it fast.

    Don't hesitate to rate my post.

  5. #5
    Join Date
    Jun 2008
    Posts
    2,477

    Re: MessageBox etc. in a constructor, would you do that?

    Quote Originally Posted by boudino View Post
    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.

  6. #6
    Join Date
    Mar 2004
    Location
    Prague, Czech Republic, EU
    Posts
    1,701

    Exclamation 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.
    • Make it run.
    • Make it right.
    • Make it fast.

    Don't hesitate to rate my post.

  7. #7
    Join Date
    Oct 2008
    Location
    Cologne, Germany
    Posts
    756

    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

  8. #8
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: MessageBox etc. in a constructor, would you do that?

    Great, now if we can just get you to use '_'.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured