Sheep are Gregarious.
By gregarious, we mean that Sheep band together and pretty much stay together when grazing etc.
Sheep see the dog as a predator, or danger, so they band together for protection and move away from the danger.
By controlling the dog, a shepherd actually controls the flock.