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