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

Dividir para Conquistar! - DCI e Engines para construção de aplicações modulares com Rails

Dividir para Conquistar! - DCI e Engines para construção de aplicações modulares com Rails

Nesta palestra será abordado o uso do framework Rails de forma não convencional. Visando ter uma melhor organização que privilegie a arquitetura de um sistema sobre as convenções do MVC do Rails

Robson Mendonça

October 18, 2014
Tweet

More Decks by Robson Mendonça

Other Decks in Programming

Transcript

  1. DIVIDIR PARA CONQUISTAR! DCI E ENGINES PARA CONSTRUÇÃO DE APLICAÇÕES

    MODULARES COM RAILS TDC 2014 - PORTO ALEGRE - @ROBSONMWOC
  2. QUEM SOU? NOME: ROBSON MENDONÇA PROFISSÃO: SOFTWARE DEVELOPER LINGUAGENS: RUBY,

    PHP, PYTHON, JAVASCRIPT, JAVA E OBJECTIVE-C E C++ FORMAÇÃO: JOGOS DIGITAIS (EM ANDAMENTO) CO-FOUNDER: HARDFUN STUDIOS
  3. ADOTE VOCÊ TAMBÉM! $ cd loja $ rails generate scaffold

    product \ name:string sku:string $ rails generate scaffold user \ name:string email:string ! $ rake db:migrate $ rails server $ open http://localhost:3000
  4. ADOTE VOCÊ TAMBÉM! # Gemfile gem ‘devise’ # authentication gem

    ‘cancan’ # authorization gem ‘will_paginate’ # pagination gem ‘bootstrap-sass’ # css framework gem ‘compass’ # sprites and others ! $ bundle install $ rails server $ open http://localhost:3000
  5. ADOTE VOCÊ TAMBÉM! # Gemfile gem ‘devise’ gem ‘cancan’ gem

    ‘will_paginate’ gem ‘bootstrap-sass’ gem ‘compass’ ! $ bundle install $ rails server $ open http://localhost:3000
  6. ARQUITETURA https://www.youtube.com/watch?v=WpkDN78P884 Ruby Midwest 2011 - Keynote: Architecture the Lost

    Years by Robert Martin MountainWest RubyConf 2013 Component-based Architectures in Ruby and Rails by Stephan Hagemann https://www.youtube.com/watch?v=-54SDanDC00
  7. RAILS ENGINES Engines can be considered miniature applications that provide

    functionality to their host applications. ! A Rails application is actually just a "supercharged" engine, with the Rails::Application class inheriting a lot of its behavior from Rails::Engine. http://guides.rubyonrails.org/engines.html
  8. PROS • Aplicação do SOLID a nível de arquitetura; •

    Testes em isolamento • Isolamento de escopo • Bom ensaio de evolução para SOA • Complexidade inicial maior; • Mais complicado de testar no início; • Não é possível fazer deploy de engines separadamente, como serviços. CONTRAS
  9. api core cmd front www financial reports delivery Básicos da

    aplicação Sempre na camada mais baixa DEPENDÊNCIA ENTRE ENGINES Específicos de components nos components
  10. Fat Models, Skinny Controllers Não mantenha lógica de negócio no

    controller! Não sabe onde por? Coloca no model. =/ DEPENDÊNCIA ENTRE ENGINES
  11. DATA, CONTEXT AND INTERACTION The data are "what the system

    is." The data part of the DCI architecture is its (relatively) static data model with relations. The data design is usually coded up as conventional classes that represent the basic domain structure of the system. DATA http://en.wikipedia.org/wiki/Data,_context_and_interaction
  12. DATA, CONTEXT AND INTERACTION The context is the class (or

    its instance) whose code includes the Roles for a given algorithm, scenario, or use case, as well as the code to map these Roles into objects at run time and to enact the use case. CONTEXT http://en.wikipedia.org/wiki/Data,_context_and_interaction
  13. DATA, CONTEXT AND INTERACTION The interaction is "what the system

    does." The interaction is implemented as Roles which are played by objects at run time. These objects combine the state and methods of a data (domain) object with methods (but no state, as Roles are stateless) from one or more Roles. INTERACTION http://en.wikipedia.org/wiki/Data,_context_and_interaction
  14. ENVELOPANDO PRA CIMA • Rails é bom, ágil, facilita muito

    a vida, mas pode te conduzir para um miojão de primeira; • Tente privilegiar sua arquitetura e não o framework; • Engines pode te ajudar a desenvolver melhores arquiteturas; • Abra seus horizontes, não se limite ao MVC.