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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:06:55+00:00 2026-05-26T09:06:55+00:00

I have created a library class CircuitController that communicates with a control circuit via

  • 0

I have created a library class CircuitController that communicates with a control circuit via serial port.

public class CircuitController
{
   // Enumerations.
   public enum Sensors { Sensor1, Sensor2, ..., Sensor15 };
   ...

   // Fields.
   private SerialPort serialPort;  // Set in constructor.
   private Dictionary<Sensors, Sensor> activeSensorCollection;
   ...

   // Properties.
   public Dictionary<Sensors, Sensor> ActiveSensors
   { get { return this.activeSensorCollection; } }       

   // Methods.
   public void SetSensorUnits(Sensors sensor, String sensorUnits)
   {
      // Creates serial command based off parameters, sends, receives, processes.
   }
   ...

   // Constructors.
   public CircuitController(...)
   {
      ... // Set CircuitController fields including nested classes.
      Sensor sensor1 = new Sensor(a,b,c,d,this);  // Link sensor to this controller instance.
      ... // Add sensors to dictionary.
   }          

   // Nested Classes.
   public class Sensor
   {
      // Fields.
      private CircuitController controller;   
      private String units;
      private Sensors sensorNumber;
      ...

      // Properties.
      public String Units
      {
         get
         {
            return this.controller.GetSensorUnits(this.sensorNumber);
         }
         set
         {
            this.controller.SetSensorUnits(this.sensorNumber, value);
          }
      }
      ...
   }

So here is my questions: Is it OK to allow the user to get/set the sensor settings through properties even though an exception may be thrown (e.g. serial communication error)?

String sensor2Units = circuitControllerInstance.ActiveSensors[Sensor2].Units'
circuitControllerInstance.ActiveSensors[Sensor1].Units = "mm";

I find this much clearer than…

String sensor2Units = circuitControllerInstance.GetSensorUnits(Sensors.Sensor2);
circuitControllerInstance.SetSensorUnits(Sensors.Sensor1, "mm");

Please note that these are simplified examples, some of the Get/Set methods have up to 5 parameters which would be a hassle to repeatedly type out. :/

  • 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-26T09:06:56+00:00Added an answer on May 26, 2026 at 9:06 am

    I would tend to avoid actually doing anything when a property is set. Instead let all the properties be set in memory, then add a “Save” method that will “save” the properties to the serial device.

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

Sidebar

Related Questions

I have created a library class for a control circuit which communicates through a
I have created a class library (assembly) that provides messaging, email and sms. This
I have created a VB.NET Class Library that exposes some COM Interop sub routines.
I have created a windows phone 7 custom class library, in that I have
I have created a maths library that operates via templates, it allows the user
I have created a library class where... public class CircuitLibrary { // Fields, properties,
I have created the WPF user control and WPF window in class library project.
I have created a VB.NET 2008 Class Library that has, for the most part,
I have created a class library in VB .NET. Some code in the library
I have created a class library called AddServiceLibrary in which I have a method

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.