Skip to content

Instantly share code, notes, and snippets.

@andrewhao
Last active October 18, 2016 16:16
Show Gist options
  • Save andrewhao/4783e3636fb1e47adfa195b749986733 to your computer and use it in GitHub Desktop.
Save andrewhao/4783e3636fb1e47adfa195b749986733 to your computer and use it in GitHub Desktop.
The Joy of Naming - Domain Driven Design
class Checkout
  def initialize(booking_amount, discount)
    @booking_amount = booking_amount
    @discount = discount
  end
 
  def total
    @booking_amount.total - @discount.calculate_amount_for(booking_amount: booking_amount)
  end
end
 
class Discount
  def initialize(amount, strategy)
    @amount = amount
  end
 
  def calculate_amount_for(booking_amount:)
    # Implementation... 
  end
end
class Coupon
  def initialize(amount, strategy)
    @amount = amount
  end
 
  def calculate_amount_for(booking_amount:)
    # Implementation... 
  end
end
class BookingAmount
  # implementation details... 
 
  def applied_coupon_amount(coupon:)
    # Implementation... 
  end
end
class Checkout
  def initialize(booking_amount, coupon)
    @booking_amount = booking_amount
    @coupon = coupon
  end
 
  def total_amount
    @booking_amount.price - @booking_amount.applied_coupon_amount(coupon: @coupon)
  end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment