According to John Collins, the story of David reads like he "was an outlaw, a deserter and a Philistine mercenary." David is certainly lifted up as a King after God's own heart, but his flaws and sins are right there out in the open as well. He is very human, and certainly not a perfect hero.
We can see the Deuteronomistic view coming out in the portrayal of David. The Deuteronomists theology was that God's covenant only continued as long as the King was faithful to the law. Jacob Wright in A Nation Conceived in Defeat, posits that this viewpoint helps to explain two main questions for the Jewish community, "Who are we?" and "What if anything still holds us together?" By showing King David's flaws it explains how his violating the law caused the calamity to come, and how important this theology was to them being a people. This style is consistent with most of the Old Testament material and further strengthens this view.