This content has been marked as final. Show 2 replies
I would say, you don't gain anything by having getters in this case.
It is quite common for one piece of code to have dependencies on other pieces of code.
It up to you to decide that when you change the type of x, the return type of the sum changes.
In the absence of other constraints, do whatever takes the least work at the time.
In the abstract case you give, there's no driver one way or the other.
It's quite natural that an OrderItem might have a cost, and something want to look at the cost and total it with an exterior sum.
It's quite natural that a RocketBooster might contribute thrust to a ThrustTotal and so use an interior sum.