It encapsulates the behavior with related data and ensures consistency.
Instance methods like calculating a line total directly interact with the object's fields, such as quantity and price, ensuring the method has all necessary data available. This design choice keeps the behavior close to the data it operates on. For example, in a CartItem class, a method calculateLineTotal() can use the item's quantity and unit price to compute the total, ensuring that any change to these fields is automatically reflected in the calculation.
Additional Notes
Why should the line total calculation be an instance method in CartItem?