This is how all dogs learn.
Finding the right motivation for each individual dog to stop a behaviour or teach a behaviour. Different types of rewards will work better for different types of dogs. Different types of punishers will be more effective for different types of dogs.
The timing of your reward or punishment is VERY important to your dog's ability to understand what is was rewarded and/or punished for. It is best that the dog is punished or rewarded as quickly as possible after the given behaviour. For example, if your dog has pooped on the floor and you come home from work and yell or rub his face in it, he doesn’t understand. This is also a great way to ruin your relationship with your dog.
Without consistency, your dog will always be confused. Lots of repetition is involved in dog training. This goes for punishment, reward, rules and boundaries etc. It is also what most owners lack and the reason for their dogs “inconsistent” behaviour.