I have to implement Java.Polynomial as a school assignment. Part of the methods are add(polynomial), multiply(polynomial) etc.
In the case of something like
p.add(q); // computes p + q
is it better to return void and keep the sum of the polynomials in p? or is it better to return a polynomial and keep the former value of p intact?
My instinct tells me that i should do the following
- implement p.add(q) as a 'destructive' method... it adds q to the value of p and stores the sum in p
- also implement a static method Polynomial.add(p,q) which returns the sum of the polynomials.
What do you think?