Java — Side Effect Methods. Good, Bad and Ugly
pc : https://unsplash.com/photos/A1HC8M5DCQc
Lexicon :
Effect, noun — a change which is a result or consequence of an action or other cause
Side, verb — support or oppose in a conflict, dispute, or debate
Side effect, noun — a secondary, typically undesirable effect
Java methods are blocks of code that can be invoked to execute particular action/logic at a high level. The required elements of a method are the method’s return type, name, a pair of parentheses, ()
, and a body between braces, {}
https://docs.oracle.com/javase/tutorial/java/javaOO/methods.html
A method can take parameters to be used for the logic in the method. Different invocations can pass different arguments to the method leading to different outcomes.
Assumption : Reader is aware of “passing mechanism in java”
A side effect method is a method which modifies some state variable value/arguments passed having a consequence beyond its scope, that is to say it has an observable effect besides returning a value (the main effect) to the invoker of the operation. In simpler terms, a method can take arguments and run some logic and return a value or not return anything.