Example 4 If the function $f(x)=\frac{1}{a} x^{2}-4 x+1, x \in[0,1]$ has a maximum value of $M(a)$ and a minimum value of $m(a)$, find the expression for $M(a)-m(a)$.
Solve $f(x)=\frac{1}{a}(x-2 a)^{2}-4 a+1, a \neq 0$.
(1) If $a>0$, (1) when $0<a \leqslant \frac{1}{4}$, $M(a)=f(0)=1, m(a)=f(2a)=1-4a$, so $M(a)-m(a)=\frac{1}{a}+4 a-4$; (2) when $\frac{1}{4}<a \leqslant \frac{1}{2}$, $M(a)=f(0)=1, m(a)=f(1)=\frac{1}{a}-3$, so $M(a)-m(a)=4 a$; (3) when $a>\frac{1}{2}$, $M(a)=f(0)=1, m(a)=f(1)=\frac{1}{a}-3$, so $M(a)-m(a)=4-\frac{1}{a}$.
In summary, $M(a)-m(a)=\left\{\begin{array}{ll}4-\frac{1}{a}, & \text { when } a>\frac{1}{2} \text {; } \\ \frac{1}{a}+4 a-4, & \text { when } 0<a \leqslant \frac{1}{4} \text {; } \\ 4 a, & \text { when } \frac{1}{4}<a \leqslant \frac{1}{2} \text {; }\end{array}\right.$