Dogs are clever creatures and despite some suggesting to the contrary - they are able to work out different behaviours are acceptable in different contexts.
Totally agree with this. My two girls never pull me when walking on a lead, as I don't allow it. They have learnt that if they pull me, we simply don't go anywhere
When they were younger and tried to pull, I just stood rigid until they stopped. However, if someone else walks them, they soon realize that I am not at the end of the lead and will take advantage by pulling
I also don't allow my dogs on the sofa so they don't attempt to get on when I am in the room. However, my youngest daughter likes cuddling up to them and they will craftily get up when I am not at home