Abiathar wore the ephod, not David: only the high priest wore it. The ephod contained the breastplate of judgment, which in turn contained the Urim and Thummim (Exodus 28:28-30). When David asked EbiatharAbiathar to bring the ephod, it wasn't so that he could wear it, but so he could ask God the question in the next verse, "Shall I pursue after this troop? shall I overtake them?"
He would have gotten the answer through the Urim and Thummim, while they were worn by Abiathar, just as Joshua would determine what to do by asking of the Urim and Thummim before Eleazar, the high priest (Numbers 27:21), meaning Joshua would ask while Eleazar was wearing them.