Against thee, thee only, have I sinned, and done that which is evil in thy sight. Ps. 51:4, R.S.V.
Why do you feel bad when you sin? Do you fear that God will think less of you? Or do you fear that someone will think less of God because of you?
That question is far more than just theological nit-picking; it touches on the deepest motivations of the heart. If your incentive for avoiding sin is so that you will not lose face before God, your basic motivation is selfish. If, on the other hand, your reason for avoiding sin is out of an intensely high regard for the reputation of One whom you love, your basic motivation is unselfish.
When we get right down to it, motivation makes all the difference. We shall have the mind of Christ only when the fires that burn behind our eyes are those of unselfish love. The law can truly be kept by those who love, for it describes how loving people act. Selfishness cannot produce unselfishness. When I have a selfish reason for wanting to become unselfish, it just won't work.
God knows that, and for this reason He gave us totally unselfish reasons for wanting to become like Him. Having entirely met all our needs (and thus healing our selfishness), He then drew us into love with Himself. More than any concerns for ourselves, we become jealous for the good reputation of our Friend. We know that others shall be making eternal decisions about Him, often based on what they see in us. And we want them to think well of Him!
David knew this, too. When he sinned, he knew exactly who had been hurt the most. Beyond the grief his sin would bring to his own life, David knew that many in Israel would wonder whether God was adequate in David's life--if David had to so clearly depart from God's will in order to get his "needs" met.
There is no evidence that David feared to approach God. He knew that his Father does not use the leverage of emotional rejection to bring one's life into line, for such would only deepen the selfish grasping that led him to his sin in the first place. He knew that God desired not groveling self-mortification but "truth in the inward being" (Ps. 51:6, R.S.V.). And God's loving acceptance made it easier for him to face that painful truth about his weaknesses.