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?