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

Your application is not your framework

Your application is not your framework

Talk given at CAS 2015 in Madrid

Enrique Comba Riepenhausen

December 03, 2015
Tweet

More Decks by Enrique Comba Riepenhausen

Other Decks in Technology

Transcript

  1. Why do we use them? • Convention • Configuration •

    Standardisation • Speed of development
  2. Convention [Code] conventions improve the readability of the software, allowing

    engineers to understand new code more quickly and thoroughly.
  3. Convention If you ship your source code as a product,

    you need to make sure it is as well packaged and clean as any other product you create.
  4. Configuration Convention over "As a general rule we don't want

    to invent an enormous java.beans.everything class that people have to inherit from. Instead we'd like the JavaBeans runtimes to provide default behaviour for 'normal' objects, but to allow objects to override a given piece of default behaviour by inheriting from some specific java.beans.something interface."
  5. # app/controllers class BlogController < ApplicationController def list @posts =

    Post.all end def show @post = Post.find(params[:id]) end end
  6. <!— app/views/blog —> <!— “list” —> <section class=“posts”> <% @posts.each

    do |post| %> <article class=“post” id=“<%= post.id %>”> <header> <h1> <%= link_to post_show_path(post), post.title %> </h1>
 </header> </article> <% end %> </section>
  7. # app/controllers class BlogController < ApplicationController def list @posts =

    Post.all end def show @post = Post.find(params[:id]) end end
  8. <!— app/views/blog —> <!— “show” —> <article class=“post” id=“<%= @post.id

    %>”> <header> <h1><%= @post.title %></h1>
 </header> <p><%= @post.body %></p> </article>
  9. <!— app/views/blog —> <!— “show with comments” —> <article class=“post”

    id=“<%= @post.id %>”> <header> <h1><%= @post.title %></h1>
 </header> <p><%= @post.body %></p> <aside> <% @post.comments.each do |comment| %> … <% end %> </aside> </article>
  10. # app/controllers class BlogController < ApplicationController def list @posts =

    Post.all end def show @post = Post.find(params[:id]) @comments = Post.comments end end
  11. # app/controllers class BlogController < ApplicationController def list @posts =

    Post.all end def show @post = Post.find(params[:id]) end end
  12. # app/controllers class PurchaseOrderController < ApplicationController def show @contract =

    Contract.find(params[:contract_id]) @purchase_order = PurchaseOrder.find(params[:id]) end end
  13. <!— app/views/purchase_order —> <article class=“purchase-order”> <header> <h1>Purchase Order No.: <%=

    @purchase_order.number %></h1>
 </header> <table> <th>…</th> <% @purchase_order.line_items.each do |item| %> … <% end %> </table> <aside> <!— extracting info about the @contract </aside> </article>
  14. # app/controllers class PurchaseOrderController < ApplicationController def show @contract =

    Contract.find(params[:contract_id]) @purchase_order = PurchaseOrder.find(params[:id]) end end
  15. # lib/orders module CasApp model Orders class PurchaseOrderForContract attr_reader :contact,

    :purchase_order def using(params) @contract = Contract.find(params[:contract_id]) @purchase_order = PurchaseOrder.find(params[:id]) end end end end
  16. # app/controllers class PurchaseOrderController < ApplicationController def show order =

    CasApp::Orders::PurchaseOrderForContract.using(params) @contract = order.contract @purchase_order = order.purchase_order end end
  17. # app/controllers class PurchaseOrderController < ApplicationController def show order =

    CasApp::Orders::PurchaseOrderForContract.using(params) @presenter = CasApp::Orders::PurchaseOrderPresenter.new(order) end end
  18. Benefits • Logical separation of concerns • Speed of testing

    • Clarity in Application Purpose • Clarity in Application Structure