Polymorphism: Music is Like Programming

April 27, 2008

In his seminal book, Object-Oriented Technology: A Manager's Guide, the author, David A. Tayor, describes polymorphism as

Hiding alternative procedures behind a common interface.
The word, polymorphism, is a Greek term meaning "many forms."  A common example of this in the programming world is a routine that calculates state sales tax.  The calling process is unaware of the different implementations (one for each state) behind the sales tax interface.

In my recent efforts to learn music, specifically the piano, I have started seeing striking parallels between some object-oriented technology concepts and music.  Polymorphism occurs in different chords derived from scales.

Each octave scale is comprised of eight steps, with the first and last step being the same note.  A C Major scale is C D E F G A B C.  Chords are combinations of three or more notes, for example C-E-G is the I chord in C Major scale.  It is called the I Chord because the lowest note of the chord is the first note of the scale.  A IV Chord is built on the 4th note of the scale. (The chords are denoted with Roman numerals, I, IV, V; but in speech are pronounced "one chord," "four chord," and "five chord.")

There are three primary chords in an octave scale: the I chord, the IV chord, and the V chord. These are the primary chords because with them you play all the notes within the scale.  The patterns for these chords is as follows: I Chord - 1 3 5, IV Chord 4 6 8, V Chord 5 7 2, where the number represents the step in the scale that is played.

For a C Major scale the I Chord is C E G, the IV Chord is F A C, and the V Chord is G B D.  The chord patterns are polymorphic.  While the pattern remains the same regardless of the scale being played, the notes do change for each scale.  The implementation of the I Chord in C Major scale is C E G, but in a D Major scale it would be D F# A.

The chords are also polymorphic in that a C Chord (C E G) occurs in multiple scales, as the I Chord in C Major, and as the IV Chord in G Major, for example.

Author's profile picture

Mark H. Nichols

I am a husband, cellist, code prole, nerd, technologist, and all around good guy living and working in fly-over country. You should follow me on Twitter.