There is a certain Signal class (much simplified, like all further code)

public class Signal { public int signalValue; public int address; } 

The program reads the configuration file, creates the required number of signal instances, each of them can be changed by the user independently.

Further, there is a certain class describing some aggregate having input / output signals, its own logic. In this case, the signal is one. In the description of the logic of the mechanism, we will use it. But the signal can be tied to one of the signals that were previously read from the configuration.

There is also a form that is universal for all mechanisms. We display all the signals through the dataGridView. In the grid, it is necessary to display certain descriptions of signals depending on the type of mechanism selected, so I started the SignalHolder class, which contains a link to the signal and its description.

 public class SignalHolder { Signal signal; string signalDescription; public SignalHolder(Signal signalArg, string descrArg) { signal = signalArg; signalDescription = descrArg; } } public class Mechanism { public static List<Mechanism> mechanismList = new List<Mechanism>(); public List<SignalHolder> signalHolderList = new List<SignalHolder>(); public Signal someAcpSignal = new Signal(); public Mechanism() { signalHolderList.Add(new SignalHolder(someAcpSignal, "Signal Description")); } } 

All is well if the signal from Mechanism is not tied to signals from the configuration. By binding, I mean something like this:

 Signal newSig = new Signal(); Mechanism m = new Mechanism(); m.someAcpSignal = newSig; 

From this point on, Signal from SignalHolder is not associated with someAcpSignal from Mechanism. Is it really necessary to rebuild signalHolderList every time, or is there a way to correctly set the link?

  • It may be to create a constructor overload with the parameter Mechanism (Signal signal). Why don't you want to? And the code that creates instances of the mechanism already makes the logic of choosing the right constructor - skubarenko
  • You can also create a second private list. In it you will put all those signals that are tied. And when you request signalHolderList, you will find the differences, and on the basis of them already display the necessary data. It would be nice if you indicated the approximate load on the system. - skubarenko
  • @nuts119 is on average for the mechanisms that need to be implemented, signals for 20. Probably, you can think about sending all signals to lists, but other than that, you need the ability to re-associate links during execution, so it won’t work through the designer. - BadIrbis
  • And the Signal description from SignalHolder, and the new (tied: newSig) are the same. Those. The description depends only on the mechanism? - skubarenko
  • @nuts119 description depends only on the mechanism, after the creation of the SignalHolder instance it will not change. Resources will be many. If I truly understood the idea with the second private list, then it would be easier to update the sheet immediately with it when each rebind. - BadIrbis

0