Last active
October 18, 2016 16:16
-
-
Save andrewhao/4783e3636fb1e47adfa195b749986733 to your computer and use it in GitHub Desktop.
The Joy of Naming - Domain Driven Design
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Coupon | |
def initialize(amount, strategy) | |
@amount = amount | |
end | |
def calculate_amount_for(booking_amount:) | |
# Implementation... | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BookingAmount | |
# implementation details... | |
def applied_coupon_amount(coupon:) | |
# Implementation... | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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