The spread of pathogens by coughing and sneezing is a method of indirect transmission of diseases.
Coughing and sneezing just release these infective organisms from the body into the surroundings.
It can be prevented by avoiding crowded areas and always wearing a face mask.