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 6679481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:21:51+00:00 2026-05-26T04:21:51+00:00

I have a library base class ( Controller ) and three sub-classes that inherit

  • 0

I have a library base class (Controller) and three sub-classes that inherit from Controller (Sensor, Output, and Environment) where:

public class Controller
{
   private SerialPort serial;
   private Sensor sensorSettings;
   private Output outputSettings;
   private Environment environmentSettings;       


   protected Dictionary<int, string> ErrorDescriptions
   { get{ this.errorDescriptions; } }

   protected SerialPort ControllerSerialPort
   { get{ this.serial; } }

   protected Sensor SensorSettings
   { get{ this.sensorSettings; } }

   // The other sub-class get properties.

   protected string SendReceive(string controllerCommand)
   { ... }

   ...
 }

 public class Sensor : Controller {...}
 ... // Other sub-classes

My question is this: Should I make the errorDescriptions static? These error descriptions will not change from controller to controller (i.e. static) but I wasn’t sure what happens in the inherited classes. Will I have to refer to them as Sensor.errorDescription in the Sensor class or will it still be Controller.errorDescription?

EDIT

Wow, I just realized I messed up big time. Here’s how it should be, I think:

private abstract class ControllerBasics
{
   protected SerialPort serial;  // The serial port to communicate with the controller.
   protected Dictionary<int, string> errorDescriptions = new Dictionary<int, string> {...};   // Possible errors for the controller (known and fixed). Won't change from controller to controller.
   public enum Sensors {One, Two, ...};   // Possible sensor selection.

   public string SendReceiveCommand(string command){...} // Method to send string command over "serial".       
}

public class OverallController : ControllerBasics // The controller class.
{       
   // Add top-level controller settings.
   private string controllerName = "Controller1"; // Have a property to get/set.
   private bool controllerON; // Controller on/off. Have property to get/set.
   ... // Other similar fields and methods.

   // Used to "sort" the controller's many settings/functions.
   private SensorSettings sensorSettings;  // Have get/set properties for these so I could do the following: overallControllerInstance.GetSensorSettingsProperty.SetActiveSensorCount(5);
   private OutputSettings outputSettings;
   private EnvironmentSettings environmentSettings;

   public OverallController(string name, string comPort, ...)  // Constructor.
   {
      // Basic settings initialization.
      // Create serial port.
      this.sensorSettings = new SensorSettings(this.serial);
      this.outputSettings = ...
}

public class SensorSettings : ControllerBasics // Class to hold the controller's specific sensor settings and their respective get/set methods. Not a new type of controller.
{
   private int activeSensorCount; // Have public method to get/set.
   ... // Others.

  public void SetActiveSensorCount(int sensorCount)
  {
     // Send command using inherited SendReceive().
  }
  ... // Others.
}

public class OutputSettings : ControllerBasics   // Same logic as SensorSettings.
{
   private string units; // Have public method to get/set.
   ... // Others.

  public string GetUnitType()  // Meters, mm, um...
  {
     // Send command using inherited SendReceive().
  }
  ... // Others.
}

public class EnvironmentSettings : ControllerBasics   // Same logic as SensorSettings.
{
   ...
}

So if errorDescriptions defined in ControllerBasics is known and fixed (and required in all derived classes) should I make it static or should I just leave it protected and each derived class will have it’s own dictionary (i.e. this.errorDescriptions)?

  • 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-26T04:21:52+00:00Added an answer on May 26, 2026 at 4:21 am

    There would only be one static variable, however many subclasses you have. Is it meant to vary by subclass, or is it truly one global mapping? If it’s the latter, then a static variable is appropriate. If not… well, there are various options, but you’d need to tell us what you’re using the map for.

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

Sidebar

Related Questions

I have a class that inherits from a base class. This base class exposes
I have an overridable sub in my base class Project1: Public Class BaseClass Protected
The current class library I am working on will have a base class (Field)
I have an existing class library with all the classes to communicate with my
I have a method like public abstract class Base { public void MethodUnderTest(); }
I have an abstract base class with a TcpClient field: public abstract class ControllerBase
Why would you have an abstract base class defining an interface for a library
I have a class that inherits a base class to which another class has
I have some base class A , and some number of inherited classes: class
I have a library A, that I develop. When I deploy it on a

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.