Locos are fitted with a multiple working type. For two locos to work together they must have the same multiple working system fitted, for example class 37s and 40s both use the blue star system so could work together. Whereas a class 56 uses the red diamond system, so could not work in multiple with either loco.
To work double headed both locos need to be coupled together with the multiple working jump cables connected. To work in top and tail the coaches must be wired through to allow the multiple working cables on both locos to be connected.
There is also the TDM (Time Division Multiplex) system where a loco can be controlled remotely. For example a class 91 being controlled from the DVT.