To factor $ a^3-a^2b+ab^2-b^3 $ we can use factoring by grouping.
Group $ \color{blue}{ a^3 }$ with $ \color{blue}{ -a^2b }$ and $ \color{red}{ ab^2 }$ with $ \color{red}{ -b^3 }$ then factor each group.
$$ \begin{aligned} a^3-a^2b+ab^2-b^3 &= ( \color{blue}{ a^3-a^2b } ) + ( \color{red}{ ab^2-b^3 }) = \\ &= \color{blue}{ a^2( a-b )} + \color{red}{ b^2( a-b ) } = \\ &= (a^2+b^2)(a-b) \end{aligned} $$