public void ConnectedPeripheral(Peripheral.Peripheral peripheral) //accepting objects of either keyboard, mouse, or screen because it is polymorphic { if (Connectors.TryGetValue(peripheral.ConnectorType, out int value)) //Validation to add peripheral based on the available connection type. { Peripherals.Add(peripheral); } else { throw new Exception(); //throw exception with there is no available ports that matches the peripheral } }
/* * A “DisconnectPeripheral()” method that accepts a type of peripheral, and will disconnect all connected peripherals of that type. */ public void DisconnectedPeripheral(Peripheral.Peripheral peripheral) { Peripherals.RemoveAll(x => x.Brand == peripheral.Brand); //remove based on Brand }