I have a class 'App' which has instances of both a 'DeviceManager' class and a windows form 'MainForm' stored as fields. MainForm is made visible by clicking a system tray icon. DeviceManager has Docked and Undocked methods, with Docked starting a synchronization operation. The Docked method should only start the operation if the MainForm is not visible.
DeviceManager doesn't have access to App's members, so it can't use App's reference to MainForm to check the form's status. Having App pass itself into DeviceManager's constructor seems like a lot of coupling when DeviceManager has no other need for such a reference (MainForm and DeviceManager are thus far unaware of each other).
I'm now considering having the setter of the App.IsUserActive property raise an event that DeviceManager can use to maintain its own 'IsUserActive' field.
Are there any other approaches I could look into?
Edit: added code to illustrate:
internal class App
{
private DeviceManager _deviceMgr;
private MainForm _mainForm;
internal App()
{
_deviceMgr = new DeviceManager();
_mainForm = new MainForm { Visible = false };
}
}
internal class DeviceManager
{
private void Docked()
{
if (!_mainForm.Visible) //can't see MainForm or App from here
{
Connect();
StartSynchronization();
}
}
private void Undocked()
{
Disconnect();
}
}