Passing parameters is common in daily programming, but should we pass parameters as object or values?
(A)
public boolean isGreaterThanZero(Payment object) {
if (object.getAmount() > 0) {
return true;
}
return false;
}
(B)
public boolean isGreaterThanZero(int amount) {
if (amount > 0) {
return true;
}
return false;
}
Neither of those.
With proper OOP, you would have isGreaterThanZero() on the Payment object, ie:
class Payment {
int amount
public boolean isGreaterThanZero() {
return amount > 0
}
}
and then:
Payment payment
boolean flag = payment.isGreaterThanZero()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With