From me, a cocktail bartender.
Shake: when you have juice, cream, or eggs
Stir: when you do not
The shaking breaks down the organic compounds in the materials, incorporating them with the alcohol. Think of it like cooking. The force of shaking acts like heat. It also aerates the drink.
Stir all cocktails that do not have any of the above. You don’t want aeration, just chilling and dilution.
James Bond specifies a shaken Martini because the bartender would normally stir it.
Most drinks these days are shaken, but it’s best to think of stirring as the default. It chills, dilutes, and combines your ingredients, while maintaining the clarity of the beverage.
Shaking also aerates the drink and mixes things more aggressively. You want to shake any time you have an ingredient that needs aeration (like citrus juice), or that needs to be broken down (like eggs or cream).
Shaking also gets things a bit colder, which is (probably, AFAIK nobody ever asked him) why Fleming liked his martinis shaken.
Latest Answers