Skip to content

Instantly share code, notes, and snippets.

@nicholasjhenry
Created November 30, 2012 13:16
Show Gist options
  • Save nicholasjhenry/4175690 to your computer and use it in GitHub Desktop.
Save nicholasjhenry/4175690 to your computer and use it in GitHub Desktop.
Dealing with Feature Envy
# Source: https://gist.github.com/4172391#gistcomment-610165
class Order
def complete_purchase(purchase)
purchase.complete(credit_card, amount)
end
def purchase_completed(transaction_reference)
update_attibutes(:transaction_reference => transaction_reference)
end
def purchase_failed(error_message)
# error handling
end
end
class Purchase
def initialize(order)
@order = order
end
def submit
order.complete_purchase(self)
end
def complete(credit_card, amount)
result = Braintree::Transaction.sale(amount: @amount, credit_card: @credit_card)
if result.success?
order.purchase_succeeded(result.transaction_reference)
else
order.purchase_failed(result.error)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment