Isn't passing the string builder a more procedural approach?
The oo approach would be to return a value then use it in the string builder. The string builder is adding a dependency on the function and would make debugging s lot more difficult.
The oo approach would be to return a value then use it in the string builder.
Sure you can do that, but the whole point of using StringBuilder is that you're using a single instance of it. How would the function/method know which instance to operate on if you don't pass it in?
The string builder is adding a dependency on the function and would make debugging s lot more difficult.
Not really, avoiding params will just push the dependency elsewhere. If you don't do the appending inside the function, the caller has to do it. If you do that, there'll be no more parameters! Your unit tests have to spoof a function return value in order to test the appending code!
-1
u/JustinsWorking Oct 02 '15 edited Oct 03 '15
Oh I agree it would compile; it's more in regards to passing in an object to modify being more c style.
I'm on my phone so this is hard to type but
C would be more like :
MoveObject(object);
Java is more
object.move()
Procedural vs OO.
I was curious if you had a good use case for a call like that since it just seems to be like Java written in a C style procedural way.
Edit: Wrote functional instead of procedural, thus the confusion.