A powerful method for constructing difference families and optimal optical orthogonal codes