Answer:
By the chords that it uses. Mainly, the melody is written, and then the harmony is put underneath it using chords that have the right note in them. For example, if a melody went D, A, B then in the key of C, the chords could be: DFA, ACE, GBD. Does this help?