Because of the aiming time, targeting is always a tough problem. As Ritter says, you only switch when it worth. There are several simple principles you can follow:
1. don't switch among targets at the same damage level.
If you lock an target, you would expect to continue attack until it run off the damage range. If you are a sniper, you can lock a target in all range. If you are a assault attacking a middle range, you can continue attacking until it flee to long range.
2. Prioritize low shield ally attacking ones
If you attack an 0% shield enemy, you may gain nothing because it is at the edge of your range. However, this is unlikely to happen if an ally is attacking it.
3. Prioritize higher threat ones.
For example, in an long range fight, you should push the snipers away first when it is possible.
This is the assault/machine gun attacking module when I was 2000.
Hope you can find the principles in this example.