Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Better: delegate credit_balance so MovieTheater only accesses Moviegoer
- class Moviegoer
- def credit_balance
- self.wallet.credit_balance # delegation
- end
- end
- class MovieTheater
- def collect_money(moviegoer,amount)
- if moviegoer.credit_balance >= amount
- moviegoer.credit_balance -= due_amount
- @collected_amount += due_amount
- else
- raise InsufficientFundsError
- end
- end
- end
Add Comment
Please, Sign In to add comment