Oxidation number of an atom can be defined as the charge on the atom if a given compound is composed of ions. For example in the compound sodium chloride (NaCl), we can calculate the oxidation number of the atoms. The two atoms in sodium chloride are sodium and chlorine. Since the total charge on the compound is zero, the sum of oxidation numbers of sodium and chlorine is also 0. Here, the oxidation number of sodium is +1 and that of chlorine is -1. We can similarly find the oxidation number of any atom in a given compound.
The definition that you wrote is a simplified scenario and something that can be used in the case of simple compounds such as, sodium chloride. For complex compounds, such as `Al_2(SO_4)_3`, etc. it becomes difficult to figure out the number of electrons that are transferred between elements. It is relatively easier to determine the charge on ions and using it to determine the charge on each atom, which is the oxidation number.
Hope this helps.