Shaking usually makes the cocktail colder and smoother. Shaking also adds a small amount of water to the cocktail, making it softer. Shaking is often used to mix lighter cocktails, such as dry martinis or martini marys.
Stirring, on the other hand, is better for stronger cocktails, such as Manhattans, Old Fashioneds, or Martinis. Stirring usually doesn't introduce too much water and will give the cocktail a more precise dosage, presenting more defined color and texture.
In short, the difference between shaking and stirring is mostly about the effect on the taste and appearance of the cocktail once it's mixed, and different types of cocktails are better suited to different mixing methods.