Drive Them to Distraction
If the urge to touch should strike your child when you're out in public, and the "this is a private moment" conversation isn't effective, try distracting your child with another activity or object. Kids often reach for their genitals when boredom sets in, so drawing their attention to a picture on the wall, an item in a storefront window, or a bubbling fountain can solve the problem immediately. Put something place-appropriate into their hands and follow it up with praises or exclamations such as, "Look at that!"
If you suspect that your child's touching is a self-comforting behavior, you might want to introduce a "safety object" such as a teddy bear or blanket. Let your child bring this object along whenever you go out and hang on to it and hug it as much as he or she needs to.