Proper program structure

My application is used to communicate with an electronic device. It reads some identification data (for example, the firmware version of the device), some configuration data and periodically data from the sensors. The program is divided into three layers:

  • Data layer - simple structures that describe how data is stored in the device’s memory.

  • Business class - classes used to communicate with the device. They contain structures from the data layer and use them to store data when reading and writing to the device.

  • Presentation level - user interface (WinForms); using businnes class classes.

Let's pretend that:

Data structures are as follows:

public struct Configuration
{
 public int Option1;
 public int Option2;
}

public struct Visualization
{
 public int Temperature;
 public int Pressure;
}

Business layer classes wrap these structures and contain the logic for communication:

public abstract class BaseEntity<DataStructureType>
{
 protected DataStructureType dataStructure;
 public BaseEntity()
 {
  this.dataStructure = new DataStructureType();
 }
 /*
  device communication logic
 */
 public abstract bool GetAllData();
}

public class ConfigurationEntity : BaseEntity<Configuration>
{
 public override bool GetAllData()
 {
  //getting configuration data from device
 }
 public int Option1
 {
  get { return this.dataStructure.Option1; }
  set { this.dataStructure.Option1 = value; }
 }
 public int Option2;
 {
  get { return this.dataStructure.Option2 * 100; }
  set { this.dataStructure.Option1 = value / 100; }
 }
}

public class VisualizationEntity : BaseEntity<Visualization>
{
 public override bool GetAllData()
 {
  //getting visualization data from device
 }
 public int Temperature
 {
  get { return this.dataStructure.temperature; }
 }
 public float Pressure;
 {
  get { return Conversions.IntToPressure(this.dataStructure.pressure); }
 }
}

Conversions, :

public static class Conversions
{
 public static float IntToPressure(int parameter)
 {
  return PressureAlgorithmA(parameter);
 }
 private static float PressureAlgorithmA(int parameter)
 {
  //some algorithm (called A) to convert binary pressure to pressure in bars
 }
}

, ( ). ​​ , , . :

public struct Configuration
{
 /*
  old options are here
 */
 //and updated goes here:
 public int Option3;
 public int Option4;
}

public class ConfigurationEntity : BaseEntity<Configuration>
{
 /*
  old code is here
 */
 //and updated goes here
 public int Option3
 {
  get { return this.dataStructure.Option3; }
  set { this.dataStructure.Option3 = value; }
 }
 public int Option4;
 {
  get { return this.dataStructure.Option4 * 20; }
  set { this.dataStructure.Option4 = value / 20; }
 }
}

:

public static class Conversions
{
 public static float IntToPressure(int parameter)
 {
  return PressureAlgorithmB(parameter);
 }
 private static float PressureAlgorithmB(int parameter)
 {
  //some algorithm (called B) to convert binary pressure to pressure in bars
 }
}

, ( Option3 Option4 ).

: ? #?

factory, Configuration ?

+3
1

( ), .

, :

BusinessLayer IPluginInterface (), , .

Communicator, BusinessLayers, .

.

+1

All Articles