1. They hold components where they need to be. But they also need to be held in place on the shaft.
2. Shafts give various components a common rotational axis.
3. Shafts transmit motion from one component to another
Let's tackle number three first.
A D-profile shaft will allow components to spin on the shaft, as well as being able to transmit power. Also its easier to go from a store bought shaft to a d-profile, than it is to put a key slot into the shaft.
But this still doesn't place a component somewhere along the length.
This is where standards come in again. If your components could be a certain thickness, then maybe we can avoid making a custom shaft, a common design will do for many different setups.
We can cut concentric slots in the axle of specified width with specific spacing, then we can make our component thickness match those measurements.
Then E-clips hold the components in place along the shaft.
Kinda like this..