"Oh, Be A Fine Girl, Kiss Me!" is a mnemonic written by Annie Jump Cannon, which is meant to help astronomy students remember stellar classification. In my opinion, only bad astronomers feel good knowing mnemonics. Nevertheless, the letter arrangement O, B, A, F, G, K, M seems a bit random, and it's difficult to memorize. Why are the brightest and the most massive stars classified as O? Why isn't it “A, B, C, D, E, F, G”?
The story of stellar classification is a combination of refashioning an older system, and trying to keep old definitions true. Originally, stars were classified by the strength of hydrogen absorption spectral lines.
Each element has a unique 'fingerprint' contained within the light coming from it. Light can be broken down into its component colors, and when that is done with the light coming from hydrogen, distinct lines are present at precise wavelengths of different hues of light.
Each other element, such as Helium, produces a different set of these lines, so it cannot be mistaken for another. The lines are produced by the unique electron configuration of every element.
Knowing the spectrum of light coming from a star, we can determine what the star is made of.
Class A stars show strong and sharp hydrogen lines, B slightly fainter ones, O have weak and barely, if at all, visible hydrogen lines. In the old system, the classes were in alphabetical order, A through Q. However, they were later rearranged based on their color, rather than in order of their weakening hydrogen lines.
At that time, much of the tedious grunt work of cataloging and classifying stars had already been done, so it was decided that the letters would only be rearranged, and that the classes themselves would not be renamed to make the new system more compatible with earlier findings. Notice that a few classes from the old system were merged; this was done to reduce the number of classes, and to make the new system simpler.
The decision to redefine stellar classification was made because the color of a star givesmuch more information about it than the hydrogen lining does, and that made the new system so popular that it eventually replaced the old one. It's surprising how much can be told about a star just by knowing its color.