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

  • SEARCH
  • Home
  • 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 9115487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:26:40+00:00 2026-06-17T04:26:40+00:00

I am just starting to use abstract classes and would like to know if

  • 0

I am just starting to use abstract classes and would like to know if I am using them in the correct manner. In my example I have a Windows Form application where Form1 is the main UI for the app. Within Form1 I have a method which writes debug messages to a richtextbox. I currently have a bunch of different classes which all have the same method in them to write message back to the main UI richtextbox. However, I was wondering if it would make sense to make this functionality part of an abstract class, an just have all of my other class inherit this functionality as shown below?

using System;
using System.Windows.Forms;

namespace abstractTest
{
    /// <summary>
    /// Main User Interface
    /// </summary>
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        public void RTBWriteLine(string message)
        {
            /* Print (append) message to the debug richtextbox */
            this.richTextBox1.AppendText(message + Environment.NewLine);

            /* Select the last entered message */
            this.richTextBox1.Select(richTextBox1.Text.Length, 0);

            /* Scroll to selected message */
            this.richTextBox1.ScrollToCaret();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            Class1 c1 = new Class1(this);
            Class2 c2 = new Class2(this);
        }
    }

    public abstract class absTest
    {
        protected Form1 MainUI;

        public virtual void MainRTBWriteLine(string msg)
        {
            if (MainUI != null)
            {
                MainUI.RTBWriteLine(msg);
            }
        }
    }

    public class Class1 : absTest
    {
        public Class1(Form callingForm)
        {
            MainUI = callingForm as Form1;
            MainRTBWriteLine("This is Class1");
        }
    }

    public class Class2 : absTest
    {
        public Class2(Form callingForm)
        {
            MainUI = callingForm as Form1;
            MainRTBWriteLine("This is Class2");
        }
    }
}

Edit:
My main goal is that I would to make DTBWriteLine(among many other methods that update the main UI is some way) to be available to all of my classes, but only have the code in one location. Right now, I have the following method (among many others) duplicated in every class I’ve created:

public virtual void MainRTBWriteLine(string msg)
{
    if (MainUI != null)
    {
        MainUI.RTBWriteLine(msg);
    }
}

If putting this in an abstract class isn’t the best approach, what is?

  • 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-06-17T04:26:41+00:00Added an answer on June 17, 2026 at 4:26 am

    Yes, this scenario is a perfect example for using an abstract class.

    When you have shared functionality in an inheritance tree.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am just starting to use Wix and would like to use heat to
Just starting to use Ruby on Rails to see what its like. I have
I'm just starting to use CxxTest and would like to test whether a std::vector
I am just starting to learn how to use RMI, and I have a
I am just starting Java RMI and have some problems with when to use
I am just starting to use Gaelyk. I was expecting it to behave like
I'm just starting to use Git, and I have a question: When I create
I'm just starting to use constants in Ruby. I have module Constants C1 =
I'm just starting to use JQuery, and I'm editing the modal popup example within
Just starting to use CodeIgniter, and I'd like to import some of my old

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.