dogs do have boundaries and do have self control, they usually have to be taught this by a person or another dog. Its actually quite fascinating to witness dog on dog correction unfold. Basically a dog can have perfect manners and recognize when another dog is acting inappropriately and correct them.
The old man dog who lives in my neighborhood was raised to have some boundaries (basically to avoid strangers,) also they let him roam around off leash. He's chill, although now they got a puppy and some kids running around, he's rather protective of them. He doesnt quite have the "correct" social etiquette, he'll bark at us / other people now to keep us away from them, and also pretends to bite us. He's an interesting little guy.
anyway I digress, dogs have personal boundaries too but usually people just ignore them. They have signs that they are uncomfortable, want personal space, etc. Some dogs were abused and have trouble adapting to people or other dogs, they're much like people in that sense.