A particularly important practice for children, but all should note, not all dogs crave a pat.
Dogs like to meet people, not for people to meet dogs. Never forget to ask permission first. Don't offer your hand out for a dog to smell it like most people are taught, it could bite it instead. I have been bitten 3 times in 43 years with thousands of dogs in my hands. Once was demonstrating exactly what not to do.
So what do you do?
Ask the owner if contact is okay.
Approach with confidence without rushing.
Try not to approach the dog and owner from directly in front, but from an angle on the dog's side, and preferably don't focus your attention on the dog.
Stand alongside the dog looking in the same direction, but not looking at the dog. I refer to this as the "equals sign".
With hands well away, allow the dog to smell your leg and whatever else it wants. When it stops smelling it has met you in its own time and in its own way, and you can now pat the dog.
If the dog moves away, ignore it and leave it alone.
Do not pat on top of the head, down the side of the face or under the chin first.If all good, it likes you, and you can be free with your praise.