He grew up raising sheep, and wrote of the streams, pastures and valleys that he experienced, and hence was able to write of the shepherd care of God. What David wrote was true of him. And you and I can write what is true of us, or take another person's writings and personalize them to make them true for us. It is exactly the same point. David writes of himself as a sheep.
Sheep are horrible at caring for themselves, absolutely defenseless, in danger from everything.
But David writes that there is nothing to be afraid of, because he has a great defender who cares for him and is capable of defending him against everything. No enemy can assail him or defeat him. And that's the point that Paul makes here. I shall not be in want. There's nothing that I need in this life, and no longing placed in me by God that will go unmet.