Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Extraindo a regra de negócio para uma nova camada
Search
Gabriel Sobrinho
May 10, 2012
Programming
0
180
Extraindo a regra de negócio para uma nova camada
Apresentado no Rails-MG em 2012
Gabriel Sobrinho
May 10, 2012
Tweet
Share
More Decks by Gabriel Sobrinho
See All by Gabriel Sobrinho
Arquiteturas Multi-Tenant RubyConf 2022
sobrinho
0
220
Introduction to Go
sobrinho
1
100
Casos de otimização em aplicações Ruby on Rails
sobrinho
0
290
Introduction to automated tests (Goiania)
sobrinho
0
130
Introduction to automated tests
sobrinho
3
220
Otimização de Aplicações RoR
sobrinho
1
260
Introdução ao React (Simplificado)
sobrinho
0
140
Algoritmos de pesquisa
sobrinho
0
640
Introdução ao Docker
sobrinho
1
100
Other Decks in Programming
See All in Programming
カスタムしながら理解するGraphQL Connection
yanagii
1
1.5k
イベント駆動で成長して委員会
happymana
1
270
Googleのテストサイズを活用したテスト環境の構築
toms74209200
0
300
Streams APIとTCPフロー制御 / Web Streams API and TCP flow control
tasshi
2
340
Ethereum_.pdf
nekomatu
0
370
ピラミッド、アイスクリームコーン、SMURF: 自動テストの最適バランスを求めて / Pyramid Ice-Cream-Cone and SMURF
twada
PRO
10
1.2k
Identifying User Idenity
moro
6
9.5k
リアーキテクチャxDDD 1年間の取り組みと進化
hsawaji
1
190
受け取る人から提供する人になるということ
little_rubyist
0
180
Kubernetes for Data Engineers: Building Scalable, Reliable Data Pipelines
sucitw
1
220
EventSourcingの理想と現実
wenas
6
2.2k
見せてあげますよ、「本物のLaravel批判」ってやつを。
77web
4
4.5k
Featured
See All Featured
Why Our Code Smells
bkeepers
PRO
334
57k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5k
Rails Girls Zürich Keynote
gr2m
93
13k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
27
4.2k
For a Future-Friendly Web
brad_frost
175
9.4k
Docker and Python
trallard
40
3.1k
Designing for humans not robots
tammielis
249
25k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.1k
The World Runs on Bad Software
bkeepers
PRO
65
11k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
31
2.7k
Navigating Team Friction
lara
183
14k
Optimising Largest Contentful Paint
csswizardry
33
2.9k
Transcript
Extraindo a regra de negócio para uma nova camada
@sobrinho • software architect @ nohup • https://github.com/sobrinho
Fat Controllers
Fat Models
Qual é o problema com essas abordagens?
Nenhum!
Por que pensar binário?
Se cada caso deve ser analisado individualmente...
Quem nunca fez um código macarrão?
None
None
Vamos fazer uma pequena aplicação
Eu preciso cadastrar meus contratos e seus itens
E também preciso cancelar os itens individualmente, salvando a data
do cancelamento
None
Rails Rails é um framework web full-stack Model-View-Controller (MVC)
Contractus ~/Code (1.9.3-p0) 21:08:25 $ rails new contractus ... create
app/controllers create app/models create app/views ...
Contractus ~/Code (1.9.3-p0) 21:08:25 $ rails new contractus ... create
app/controllers create app/models create app/views ...
Contractus ~/Code (1.9.3-p0) 21:08:25 $ rails new contractus ... create
app/controllers create app/models create app/views ...
Contractus ~/Code (1.9.3-p0) 21:08:25 $ rails new contractus ... create
app/controllers create app/models create app/views ...
Contractus ~/Code (1.9.3-p0) 21:08:25 $ rails new contractus ... create
app/controllers create app/models create app/views ...
Contractus ~/Code (1.9.3-p0) 21:08:25 $ rails new contractus ... create
app/controllers create app/models create app/views ...
Contractus ~/Code (1.9.3-p0) 21:08:25 $ rails new contractus ... create
app/controllers create app/models create app/views ...
Contractus ~/Code/contractus (1.9.3-p0) (master) 21:10:52 $ rails generate scaffold contract
name:string 21:21:49 $ rails generate scaffold item contract:references name:string price:decimal canceled_at:date
Contractus ~/Code/contractus (1.9.3-p0) (master) 21:10:52 $ rails generate scaffold contract
name:string 21:21:49 $ rails generate scaffold item contract:references name:string price:decimal canceled_at:date
Contractus ~/Code/contractus (1.9.3-p0) (master) 21:10:52 $ rails generate scaffold contract
name:string 21:21:49 $ rails generate scaffold item contract:references name:string price:decimal canceled_at:date
Contractus ~/Code/contractus (1.9.3-p0) (master) 21:10:52 $ rails generate scaffold contract
name:string 21:21:49 $ rails generate scaffold item contract:references name:string price:decimal canceled_at:date
Contractus ~/Code/contractus (1.9.3-p0) (master) 21:10:52 $ rails generate scaffold contract
name:string 21:21:49 $ rails generate scaffold item contract:references name:string price:decimal canceled_at:date
Contractus ~/Code/contractus (1.9.3-p0) (master) 21:10:52 $ rails generate scaffold contract
name:string 21:21:49 $ rails generate scaffold item contract:references name:string price:decimal canceled_at:date
Contractus ~/Code/contractus (1.9.3-p0) (master) 21:10:52 $ rails generate scaffold contract
name:string 21:21:49 $ rails generate scaffold item contract:references name:string price:decimal canceled_at:date
Contractus ~/Code/contractus (1.9.3-p0) (master) 21:10:52 $ rails generate scaffold contract
name:string 21:21:49 $ rails generate scaffold item contract:references name:string price:decimal canceled_at:date
Contractus ~/Code/contractus (1.9.3-p0) (master) 21:10:52 $ rails generate scaffold contract
name:string 21:21:49 $ rails generate scaffold item contract:references name:string price:decimal canceled_at:date
Contractus ~/Code/contractus (1.9.3-p0) (master) 21:10:52 $ rails generate scaffold contract
name:string 21:21:49 $ rails generate scaffold item contract:references name:string price:decimal canceled_at:date
Contractus ~/Code/contractus (1.9.3-p0) (master) 21:10:52 $ rails generate scaffold contract
name:string 21:21:49 $ rails generate scaffold item contract:references name:string price:decimal canceled_at:date
Contractus ~/Code/contractus (1.9.3-p0) (master) 21:10:52 $ rails generate scaffold contract
name:string 21:21:49 $ rails generate scaffold item contract:references name:string price:decimal canceled_at:date
Contractus ~/Code/contractus (1.9.3-p0) (master) 21:10:52 $ rails generate scaffold contract
name:string 21:21:49 $ rails generate scaffold item contract:references name:string price:decimal canceled_at:date
Contractus ~/Code/contractus (1.9.3-p0) (master) 21:10:52 $ rails generate scaffold contract
name:string 21:21:49 $ rails generate scaffold item contract:references name:string price:decimal canceled_at:date
Fat Controller
None
~/Code/contractus (1.9.3-p0) ((v0.1.0)) 07:28:35 $ time rspec spec/controllers ................................. Finished
in 0.42347 seconds 33 examples, 0 failures real 0m7.831s user 0m3.328s sys 0m0.651s
Fat Model
None
~/Code/contractus (1.9.3-p0) ((v0.2.0)) 02:28:40 $ time rspec spec/models . Finished
in 0.02556 seconds 1 example, 0 failures real 0m3.048s user 0m2.621s sys 0m0.413s
Business
None
~/Code/contractus (1.9.3-p0) ((v0.3.0)) 02:29:59 $ time rspec spec/business . Finished
in 0.00072 seconds 1 example, 0 failures real 0m0.535s user 0m0.397s sys 0m0.088s
Fluxo mais simples Controller x Business x Model
Testes isolados Regra de negócio não deve depender de absolutamente
nada para ser testada
Manutenção fácil Como proceder se somente os itens das últimas
24h puderem ser cancelados?
Dúvidas?
Obrigado!