model of the colossus @ café com dev
DESCRIPTION
Saiba como não deixar seu model virar um ameaçador Colosso. Vídeo da palestra em https://www.eventials.com/pt-br/helabs/model-of-the-colossus/TRANSCRIPT
![Page 1: Model of the colossus @ Café com Dev](https://reader034.vdocuments.mx/reader034/viewer/2022051612/54bd18654a7959135f8b45d0/html5/thumbnails/1.jpg)
Model of the Colossus
![Page 2: Model of the colossus @ Café com Dev](https://reader034.vdocuments.mx/reader034/viewer/2022051612/54bd18654a7959135f8b45d0/html5/thumbnails/2.jpg)
![Page 3: Model of the colossus @ Café com Dev](https://reader034.vdocuments.mx/reader034/viewer/2022051612/54bd18654a7959135f8b45d0/html5/thumbnails/3.jpg)
![Page 4: Model of the colossus @ Café com Dev](https://reader034.vdocuments.mx/reader034/viewer/2022051612/54bd18654a7959135f8b45d0/html5/thumbnails/4.jpg)
@maurogeorgemaurogeorge.github.comaprenderphp.com.br
Mauro George
![Page 5: Model of the colossus @ Café com Dev](https://reader034.vdocuments.mx/reader034/viewer/2022051612/54bd18654a7959135f8b45d0/html5/thumbnails/5.jpg)
Seu model, um grande colosso
![Page 6: Model of the colossus @ Café com Dev](https://reader034.vdocuments.mx/reader034/viewer/2022051612/54bd18654a7959135f8b45d0/html5/thumbnails/6.jpg)
Mas por que isto acontece?
![Page 7: Model of the colossus @ Café com Dev](https://reader034.vdocuments.mx/reader034/viewer/2022051612/54bd18654a7959135f8b45d0/html5/thumbnails/7.jpg)
Um pouco de história
![Page 8: Model of the colossus @ Café com Dev](https://reader034.vdocuments.mx/reader034/viewer/2022051612/54bd18654a7959135f8b45d0/html5/thumbnails/8.jpg)
Rails 15 minutes blog
Começamos bem
![Page 9: Model of the colossus @ Café com Dev](https://reader034.vdocuments.mx/reader034/viewer/2022051612/54bd18654a7959135f8b45d0/html5/thumbnails/9.jpg)
Começamos bem
MVC
![Page 10: Model of the colossus @ Café com Dev](https://reader034.vdocuments.mx/reader034/viewer/2022051612/54bd18654a7959135f8b45d0/html5/thumbnails/10.jpg)
Começamos bem
Rails way
![Page 11: Model of the colossus @ Café com Dev](https://reader034.vdocuments.mx/reader034/viewer/2022051612/54bd18654a7959135f8b45d0/html5/thumbnails/11.jpg)
Começamos bem
Migração de outras linguagens direto para o RailsDesde que mude o mindset
![Page 12: Model of the colossus @ Café com Dev](https://reader034.vdocuments.mx/reader034/viewer/2022051612/54bd18654a7959135f8b45d0/html5/thumbnails/12.jpg)
Inicia a confusão para novatos
2 Stacks
![Page 13: Model of the colossus @ Café com Dev](https://reader034.vdocuments.mx/reader034/viewer/2022051612/54bd18654a7959135f8b45d0/html5/thumbnails/13.jpg)
Inicia a confusão para novatos
37 Signals stackERB for view templatesMySQL for databasesMiniTest for testingFat Models, Skinny Controllers
![Page 14: Model of the colossus @ Café com Dev](https://reader034.vdocuments.mx/reader034/viewer/2022051612/54bd18654a7959135f8b45d0/html5/thumbnails/14.jpg)
Inicia a confusão para novatos
Prime stackHaml for view templatesPostgreSQL for databasesRspec/Cucumber for testingSkinny models, controllers, and a service layer
![Page 15: Model of the colossus @ Café com Dev](https://reader034.vdocuments.mx/reader034/viewer/2022051612/54bd18654a7959135f8b45d0/html5/thumbnails/15.jpg)
AR quebra o SRP
Alto acoplamento - Callback - Observer - Finders
Falta de coesão - Salva - Envia e-mail - Posta no Facebook
![Page 16: Model of the colossus @ Café com Dev](https://reader034.vdocuments.mx/reader034/viewer/2022051612/54bd18654a7959135f8b45d0/html5/thumbnails/16.jpg)
Anti-patternModel gerando conteúdo para view
![Page 17: Model of the colossus @ Café com Dev](https://reader034.vdocuments.mx/reader034/viewer/2022051612/54bd18654a7959135f8b45d0/html5/thumbnails/17.jpg)
SoluçãoDecorator & Presenter
![Page 18: Model of the colossus @ Café com Dev](https://reader034.vdocuments.mx/reader034/viewer/2022051612/54bd18654a7959135f8b45d0/html5/thumbnails/18.jpg)
SoluçãoDecorator
Para quando lidamos com apenas uma entidade
![Page 19: Model of the colossus @ Café com Dev](https://reader034.vdocuments.mx/reader034/viewer/2022051612/54bd18654a7959135f8b45d0/html5/thumbnails/19.jpg)
Anti-pattern
![Page 20: Model of the colossus @ Café com Dev](https://reader034.vdocuments.mx/reader034/viewer/2022051612/54bd18654a7959135f8b45d0/html5/thumbnails/20.jpg)
Solução
app/decorators/user_decorator.rb
![Page 21: Model of the colossus @ Café com Dev](https://reader034.vdocuments.mx/reader034/viewer/2022051612/54bd18654a7959135f8b45d0/html5/thumbnails/21.jpg)
Solução
![Page 22: Model of the colossus @ Café com Dev](https://reader034.vdocuments.mx/reader034/viewer/2022051612/54bd18654a7959135f8b45d0/html5/thumbnails/22.jpg)
SoluçãoPresenter
Para quando lidamos com N entidades
![Page 23: Model of the colossus @ Café com Dev](https://reader034.vdocuments.mx/reader034/viewer/2022051612/54bd18654a7959135f8b45d0/html5/thumbnails/23.jpg)
Anti-pattern
Método de Post ou User?
![Page 24: Model of the colossus @ Café com Dev](https://reader034.vdocuments.mx/reader034/viewer/2022051612/54bd18654a7959135f8b45d0/html5/thumbnails/24.jpg)
Solução
app/presenters/writter_post_presenter.rb
![Page 25: Model of the colossus @ Café com Dev](https://reader034.vdocuments.mx/reader034/viewer/2022051612/54bd18654a7959135f8b45d0/html5/thumbnails/25.jpg)
Solução
![Page 26: Model of the colossus @ Café com Dev](https://reader034.vdocuments.mx/reader034/viewer/2022051612/54bd18654a7959135f8b45d0/html5/thumbnails/26.jpg)
SoluçãoPrefira esta abordagem a helpers
Helpers são procedurais
![Page 27: Model of the colossus @ Café com Dev](https://reader034.vdocuments.mx/reader034/viewer/2022051612/54bd18654a7959135f8b45d0/html5/thumbnails/27.jpg)
Anti-patternModel Callbacks
![Page 28: Model of the colossus @ Café com Dev](https://reader034.vdocuments.mx/reader034/viewer/2022051612/54bd18654a7959135f8b45d0/html5/thumbnails/28.jpg)
Anti-pattern
![Page 29: Model of the colossus @ Café com Dev](https://reader034.vdocuments.mx/reader034/viewer/2022051612/54bd18654a7959135f8b45d0/html5/thumbnails/29.jpg)
SoluçãoService
![Page 30: Model of the colossus @ Café com Dev](https://reader034.vdocuments.mx/reader034/viewer/2022051612/54bd18654a7959135f8b45d0/html5/thumbnails/30.jpg)
Solução
app/services/post_notify_users_service.rb
![Page 31: Model of the colossus @ Café com Dev](https://reader034.vdocuments.mx/reader034/viewer/2022051612/54bd18654a7959135f8b45d0/html5/thumbnails/31.jpg)
Solução
![Page 32: Model of the colossus @ Café com Dev](https://reader034.vdocuments.mx/reader034/viewer/2022051612/54bd18654a7959135f8b45d0/html5/thumbnails/32.jpg)
Anti-patternModel Salvando N models
![Page 33: Model of the colossus @ Café com Dev](https://reader034.vdocuments.mx/reader034/viewer/2022051612/54bd18654a7959135f8b45d0/html5/thumbnails/33.jpg)
Anti-pattern
![Page 34: Model of the colossus @ Café com Dev](https://reader034.vdocuments.mx/reader034/viewer/2022051612/54bd18654a7959135f8b45d0/html5/thumbnails/34.jpg)
SoluçãoForm Object
![Page 35: Model of the colossus @ Café com Dev](https://reader034.vdocuments.mx/reader034/viewer/2022051612/54bd18654a7959135f8b45d0/html5/thumbnails/35.jpg)
Solução
lib/active_model/model.rb
Já vem no rails 4
Gem active_attr
Gem virtus
![Page 36: Model of the colossus @ Café com Dev](https://reader034.vdocuments.mx/reader034/viewer/2022051612/54bd18654a7959135f8b45d0/html5/thumbnails/36.jpg)
Solução
app/models/user_with_post.rb
Model nem sembre herda de AR
![Page 37: Model of the colossus @ Café com Dev](https://reader034.vdocuments.mx/reader034/viewer/2022051612/54bd18654a7959135f8b45d0/html5/thumbnails/37.jpg)
Solução
![Page 38: Model of the colossus @ Café com Dev](https://reader034.vdocuments.mx/reader034/viewer/2022051612/54bd18654a7959135f8b45d0/html5/thumbnails/38.jpg)
ActiveSupport::ConcernsPrefira as abordagem utilizando POROsActiveSupport::Concerns taca tudo para
debaixo dos panos
![Page 39: Model of the colossus @ Café com Dev](https://reader034.vdocuments.mx/reader034/viewer/2022051612/54bd18654a7959135f8b45d0/html5/thumbnails/39.jpg)
Bad SmellsMeu Model está virando um Colosso?
![Page 40: Model of the colossus @ Café com Dev](https://reader034.vdocuments.mx/reader034/viewer/2022051612/54bd18654a7959135f8b45d0/html5/thumbnails/40.jpg)
Bad SmellsDiversos métodos com nome de outra
entidade
![Page 41: Model of the colossus @ Café com Dev](https://reader034.vdocuments.mx/reader034/viewer/2022051612/54bd18654a7959135f8b45d0/html5/thumbnails/41.jpg)
Bad SmellsN métodos recebendo o mesmo paramêtro
![Page 42: Model of the colossus @ Café com Dev](https://reader034.vdocuments.mx/reader034/viewer/2022051612/54bd18654a7959135f8b45d0/html5/thumbnails/42.jpg)
N métodos privados que são usados em apenas um método
Bad Smells
![Page 43: Model of the colossus @ Café com Dev](https://reader034.vdocuments.mx/reader034/viewer/2022051612/54bd18654a7959135f8b45d0/html5/thumbnails/43.jpg)
Classe gigante(Provavelmente uma God Class)
Prefira N classes pequenas
Bad Smells
![Page 44: Model of the colossus @ Café com Dev](https://reader034.vdocuments.mx/reader034/viewer/2022051612/54bd18654a7959135f8b45d0/html5/thumbnails/44.jpg)
Pro FuturoDCI
![Page 45: Model of the colossus @ Café com Dev](https://reader034.vdocuments.mx/reader034/viewer/2022051612/54bd18654a7959135f8b45d0/html5/thumbnails/45.jpg)
Crie classes
Quebre Model e Classes grandes em classes menores
Classes que façam apenas uma coisa bem feita
Conclusão
![Page 46: Model of the colossus @ Café com Dev](https://reader034.vdocuments.mx/reader034/viewer/2022051612/54bd18654a7959135f8b45d0/html5/thumbnails/46.jpg)
@maurogeorgemaurogeorge.github.comaprenderphp.com.br
Mauro George
![Page 47: Model of the colossus @ Café com Dev](https://reader034.vdocuments.mx/reader034/viewer/2022051612/54bd18654a7959135f8b45d0/html5/thumbnails/47.jpg)
Referênciashttp://rubyweekly.com/archive/124.htmlhttp://rubyweekly.com/archive/126.htmlhttp://robots.thoughtbot.com/post/14825364877/evaluating-alternative-decorator-implementations-inhttp://mikepackdev.com/blog_posts/31-exhibit-vs-presentersamuelmullen.com/2013/05/the-problem-with-rails-callbackshttp://blog.codeclimate.com/blog/2012/10/17/7-ways-to-decompose-fat-activerecord-models/http://rubysource.com/ddd-for-rails-developers-part-1-layered-architecture/http://blog.plataformatec.com.br/2012/03/barebone-models-to-use-with-actionpack-in-rails-4-0/http://www.youtube.com/watch?v=DC-pQPq0acs