The characters on the show could very well be manifestations of Ted's personality or wishes. Robin is his idealized love interest, Barney is the ideal womanizer single Ted wished to be, and Lily and Marshall are the ideal couple Ted wishes to be part of some day.