Principles of Cavity Design