Reputation: 353
I need help with the following design. Basically I have a Main form which initializes a class called Settings. When the user clicks on a form called CommunicationsSetupForm, Main passes the Settings class in its ctor. From this CommunicationsSetupForm, the user can change settings such as the type of communication (RS232, RS485, TCP/IP, etc), baud rates, COM port names, etc.
Once this is done, focus is back to the Main form. From here, the user can send a packet to the respective hardware, such as a RUN packet. The packet is initalized through the Init Packet class, which also takes in the Settings class in its CTOR, than InitalizePacket calls PacketGenerate, which also passes the Settings class in its CTOR, and than finally CommunicationMediator is called via an event from PacketGenerate. CommunicationMediator is actually initialized in the Main Form, and also takes in the Settings class via its CTOR. Below is a picture of what is going on and I hope it makes the situation a little more clear:
My question is, what is the best way for CommunicationMediator to know if the Settings class has changed. For example, the user now has changed the baud rate to 300 from 9600. From my research, I have read about "Deep Copy" and a way to implement it: How do you do a deep copy of an object in .NET (C# specifically)?. Using this technique, I can create a non-referenced copy of the class called OldSettings and compare it with the current Settings class each time I need to send something out via the hardware. If OldSettings != Settings, I change the settings on the hardware first.
How can I compare an old Settings class with the current Settings class if I implement it this way? Is this the best way for CommunicationMediator to check if the Settings class has changed?
Upvotes: 3
Views: 114
Reputation: 564413
Your Settings
class could just implement INotifyPropertyChanged. This is a standard interface in the framework which allows you to subscribe to notifications if properties within a class have changed, and is far simpler than deep copying and comparing each time.
Upvotes: 4