10 ms·
None of those three examples expresses intent. Why are you crediting 100 dollars? Is it a refund, is it a loyalty reward, a signup bonus? account.award_loy
by glenjamin 14y ago
None of those three examples expresses intent. Why are you crediting 100 dollars? Is it a refund, is it a loyalty reward, a signup bonus?
account.award_loyalty_bonus()
account.award_welcome_bonus()
This is closer to the first option, but will actually model the behaviour of your application using domain terms.
- rprasad 14y agoIf I understand what benjamin is saying, these would be written as: account.process_transaction(new loyalty_bonus(bonus_amount)) or possibly account.process_transaction(new bonus(loyalty_bonus_amount)) depending on the business logic.
- glenjamin 14y agoNot quite, the point is that the caller doesn't care how much the loyalty bonus is, only that the bonus it is awarding is for loyalty. The value of the bonus then gets captured in the domain object. If there is enough related logic to justify having a loyalty bonus object, then you might have account.award(LoyaltyBonus.new) Or, if we're going to start slicing things up like this, we might go for: LoyaltyBonus.award_to(account)