Why do cactus's have spikes?

to prevent it from being eaten by predators.