Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Clean Architecture - Arena TOTVS 2015

bezelga
November 25, 2015
190

Clean Architecture - Arena TOTVS 2015

bezelga

November 25, 2015
Tweet

Transcript

  1. context 'enough money to transfer' do it 'responds true' do

    expect(transfer).to be true end it 'debits the source account' do expect{ transfer }.to change{ source_account_balance }.by(- amount) end it 'credits the destination account' do expect{ transfer }.to change{ destination_account_balance }.by(amount) end end PRIMARY course
  2. context 'not enough money to transfer' do it 'cancels the

    transfer and responds false' do expect(transfer).to be false end it 'does not change the accounts balance' do expect{ transfer }.to_not change{ source_account_balance } expect{ transfer }.to_not change{ destination_account_balance } end end EXCEPTION COURSE
  3. FFF

  4. module Core class TransferMoney def self.transfer_money(source_account_id:, destination_account_id:, amount:) balance =

    Core.get_balance(account_id: source_account_id) return false if balance < amount ActiveRecord::Base.transaction do Trade.create!(account_id: source_account_id, amount: -amount) Trade.create!(account_id: destination_account_id, amount: amount) end end end end core/transfer_money.rb
  5. class TransferMoneyController < ApplicationController before_action :load_balance def create if Core.transfer_money(source_account_id:

    source_account_id, destination_account_id: destination_account_id, amount: amount) redirect_to new_transfer_money_path else flash[:error] = 'Not enough money on the source account' render :new end end private def load_balance @balance = Core.get_balance(account_id: current_account_id) end end
  6. a key, longstanding hallmark of a good program is that

    it separates what is stable from what changes in the interest of good maintenance. - Trygve Reenskaug
  7. Eric Evans Don’t try yo apply DDD to everything. Draw

    a context map and decide on where you will make a push for DDD and where you will not .
  8. Developer #1 Developer #2 The Boss The Mastermind Tio Roberto

    Domain Father Advisor Presenter CAST TYRION LANNISTER Jon SNOW SHERKLOCKS’ BROTHER IVAR JACOBSON UNCLE BOB ERIC EVANS ROBERT DUVAL FABIANO BESELGA by @fbzga