Last active
December 19, 2015 22:48
-
-
Save joakimk/6029651 to your computer and use it in GitHub Desktop.
The functional core, imperative shell pattern as I see it. I use this quite a bit. Makes the code simpler to understand and test.
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
# Functional core | |
# Tested with unit tests. Mostly simple state based tests (like: invoice.gross_amount.should == 200). | |
class BuildInvoice | |
def build | |
# build invoice in memory.. | |
end | |
end | |
# Imperative shell | |
# Usually just tested with a single test to ensure it stores data in the database | |
class InvoiceCreator | |
def self.create(order) | |
# load needed data from db | |
invoice = BuildInvoice.new(order, ...).build | |
# save changes to db | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment