Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6598297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:19:40+00:00 2026-05-25T18:19:40+00:00

I have a winforms application and I’m not following any kind of design pattern.

  • 0

I have a winforms application and I’m not following any kind of design pattern. My problem is, I have these base classes which contain all my business logic. When ever an exception occurs or I need to display a dialog box to the user, I have written the code directly into the base classes where I need it.

I know that I need to separate my business logic and display logic, so I wrote a static class that includes the methods that I need to display the messages with.

My question is, is there an easier way to separate business logic from the display?

my static methods look like this,

public static void DisplayMessage(string message) 
    {
        MessageBox.Show(message);
    }

 public static bool DisplayDialogBox(string message,string caption ) 
    {
        DialogResult newresult = new DialogResult();

        newresult = MessageBox.Show(message,caption,MessageBoxButtons.OKCancel);

        if (newresult == DialogResult.OK)
        {
            return true;
        }
        else 
        {
            return false;
        }  

So I’ll be calling these methods from the base classes, like

MsgDisplay.DisplayMessage(e.Message);

and is this method a good practice?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T18:19:41+00:00Added an answer on May 25, 2026 at 6:19 pm

    No, this method is not a good practice. There is no any difference between your class and MessageBox class.
    See, with your class:

    MsgDisplay.DisplayMessage(e.Message);
    

    and just using MessageBox

    MessageBox.Show(e.Message);
    

    This wrapper doesn’t provide any additional functionality.
    If you want to separate business logic and ui, then you have to break down your methods and display message only in UI layer.
    And, small point. Instead of:

    if (newresult == DialogResult.OK)
        {
            return true;
        }
        else 
        {
            return false;
        }
    

    type just:

    return newresult==DialogResult.OK
    

    UPDATE:
    If all you want to display is exception message then you should catch exception and show message on UI layer. So in your business class instead of displaying message:

    void foo() {
       try {
           //some code here
       }
       catch(FooException fe) {
           MessageBox.Show(fe.Message);
       }
    }
    

    throw exception to the ui layer:

    void foo() {
       try {
           //...
       }
       catch(FooException fe) {
           //throw new BarException("Error occured: "+fe.Message); //if you want to customize error message.
           throw; //If you don't need to change the message consider to not catch exception at all
       }
    }
    

    and then display the message outside of the business logic:

    void fooButton_Click(object sender, EventArgs args) {
       try {
            fooBusinessClass.foo();
       } catch(FooException fe) {
            //if(MessageBox.Show(fe.Message)==DialogResult.OK) fooBusinessClass.continuefoo(); //if you have several options
            MessageBox.Show(fe.Message);
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Winforms application, which hosts two PDF Viewers (Unmanaged C++) in its
I have a WinForms application, which I need to support in multiple languages. I
I have a winforms application in which some of the data is stored in
I have a WinForms application. I've populated my ComboBox with the following code: cboGridSize.Items.Clear();
I have a Winforms application that executes a stored procedure which examines several rows
I have a WinForms application in which my background worker is doing a sync
I have a WinForms application with a user control in which I change the
I have a winforms application which is deployed with a standard windows installer (MSI),
I have a WinForms application which can be localized through satellite assemblies for the
I have winforms application which uses nhibernate and active records to access the database.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.