It's a difficult one. At 4yrs, I think the most important thing, as has been mentioned, is "keep within my sight and don't run off" and "don't go off with anyone unless I've said it is OK"
When dd was that age, I just explained that nearly everybody is very nice and kind to children, but there are a very few people in the world who are not nice and she shouldn't get in to cars or accept sweets from strangers even if they say that "Mummy said it was ok"
When she was older (around 6.5/7yrs) we starting doing a few role play exercises (keeping it fun and upbeat) about possible different scenarios. I explained that is was OK to shout "no" loudly and run away if an adult or older child tried to speak/grab/or touch her in a way she didn't like and, in those circumstances, it wasn't impolite to do so. She loved the shouting bit and still remembers it now!!
I also told her that if she needed help to run to a mother with other children (someone pushing a pram for example) and go where there are lots of other people, on the grounds that this would probably be a reasonable bet!
We also made sure she knew what to do if she got lost and that she knew her full name, address and phone number but not to give this information out to anyone at random!
And now she's 9 yrs, that, generally speaking, if you go and seek help from someone such as a policeman or someone working at shop till for example, then that's probably oK - BUT - if someone approaches you - be VERY suspicious - even if they say they know me or a friend etc. I've explained a true friend wouldn't do this.
More info here
For older dc here
For teenagers & adults here