One day my settlement got attacked by bandits and one of them got trapped in a cage. This gave me the idea to outline my wall in cages and every time bandits attacked they just got trapped in the cages before actually attacking. You can also tame the bandits and get basically an unlimited settlers (as long as the bandits are actually tamed.) which makes the ultimate defense.
External link →