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
230
Otimização de Aplicações RoR
sobrinho
1
270
Introdução ao React (Simplificado)
sobrinho
0
150
Algoritmos de pesquisa
sobrinho
0
650
Introdução ao Docker
sobrinho
1
100
Other Decks in Programming
See All in Programming
「とりあえず動く」コードはよい、「読みやすい」コードはもっとよい / Code that 'just works' is good, but code that is 'readable' is even better.
mkmk884
6
1.3k
月刊 競技プログラミングをお仕事に役立てるには
terryu16
1
1.1k
Внедряем бюджетирование, или Как сделать хорошо?
lamodatech
0
880
命名をリントする
chiroruxx
1
580
traP の部内 ISUCON とそれを支えるポータル / PISCON Portal
ikura_hamu
0
140
週次リリースを実現するための グローバルアプリ開発
tera_ny
1
780
MCP with Cloudflare Workers
yusukebe
2
270
毎日13時間もかかるバッチ処理をたった3日で60%短縮するためにやったこと
sho_ssk_
1
500
歴史と現在から考えるスケーラブルなソフトウェア開発のプラクティス
i10416
0
260
非ブラウザランタイムとWeb標準 / Non-Browser Runtimes and Web Standards
petamoriken
0
410
CQRS+ES の力を使って効果を感じる / Feel the effects of using the power of CQRS+ES
seike460
PRO
0
230
サーバーゆる勉強会 DBMS の仕組み編
kj455
1
210
Featured
See All Featured
Testing 201, or: Great Expectations
jmmastey
41
7.2k
Building a Scalable Design System with Sketch
lauravandoore
460
33k
Side Projects
sachag
452
42k
Building Applications with DynamoDB
mza
92
6.1k
Thoughts on Productivity
jonyablonski
68
4.4k
Typedesign – Prime Four
hannesfritz
40
2.5k
Fashionably flexible responsive web design (full day workshop)
malarkey
406
66k
jQuery: Nuts, Bolts and Bling
dougneiner
62
7.6k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
120k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
251
21k
Measuring & Analyzing Core Web Vitals
bluesmoon
5
190
The Illustrated Children's Guide to Kubernetes
chrisshort
48
49k
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!