Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Aki Salmi: Object Oriented Views at I T.A.K.E. Unconference 2015

393 views

Published on

Aki Salmi: Object Oriented Views at I T.A.K.E. Unconference 2015

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Aki Salmi: Object Oriented Views at I T.A.K.E. Unconference 2015

  1. 1. Object Oriented Views Aki Salmi @rinkkasatiainen Wednesday, May 20, 15
  2. 2. Programmer @Ambientia skype: @rinkkasatiainen twitter: @rinkkasatiainen email: aki.salmi@iki.fi Wednesday, May 20, 15
  3. 3. Wednesday, May 20, 15
  4. 4. Content • Background • A way to solve • Discussion • Open Space: Mob Programming? Wednesday, May 20, 15
  5. 5. Very Brief Background • Confluence plugin Wednesday, May 20, 15
  6. 6. We have all seen Wednesday, May 20, 15
  7. 7. Controllers like Wednesday, May 20, 15
  8. 8. This Wednesday, May 20, 15
  9. 9. /INDEX (1 of many actions) Params Service “DAO” “or not DAO” DAO-DAO-DAO Service Service Domain Service Render Wednesday, May 20, 15
  10. 10. Not that, not today Wednesday, May 20, 15
  11. 11. Let’s assume we’re working with thin controllers Wednesday, May 20, 15
  12. 12. Have we seen Wednesday, May 20, 15
  13. 13. views like Wednesday, May 20, 15
  14. 14. this Only today: logic in a view Wednesday, May 20, 15
  15. 15. So how then? Wednesday, May 20, 15
  16. 16. How about Code I’ve written myself? Wednesday, May 20, 15
  17. 17. Not much better Wednesday, May 20, 15
  18. 18. A Deeper Dive Params BUILD CONTEXT GET MODEL RENDER OR RENDER Wednesday, May 20, 15
  19. 19. But there is a catch Wednesday, May 20, 15
  20. 20. Render Many Blogs Or 1, or 0 Wednesday, May 20, 15
  21. 21. ... based on object types Wednesday, May 20, 15
  22. 22. Build a ‘different’ domain entity? Build ‘real’ Domain Build ‘real’ Domain Wednesday, May 20, 15
  23. 23. Build a ‘different’ Context BUILD context Diff context no context Wednesday, May 20, 15
  24. 24. Render ‘different’ template Templ_0 Templ_1 Templ_n Wednesday, May 20, 15
  25. 25. Seems like a violation of SRP (Single Responsibility Principle) Wednesday, May 20, 15
  26. 26. What did we see • build parameters • build context (on 2 places) • build domain • render different data, differently, based on the domain entity Wednesday, May 20, 15
  27. 27. Visually Controller HTTP GET Domain View 0 View 1 View N Wednesday, May 20, 15
  28. 28. It works Wednesday, May 20, 15
  29. 29. ..sort of • most of the bugs I introduced, were on this behavior of the system. • This class • Concepts introduced by this class • Integration with Confluence API • especially ‘null’s Wednesday, May 20, 15
  30. 30. What IF Controller HTTP GET Domain View 0 View 1 View N Wednesday, May 20, 15
  31. 31. What IF... C’s responsibility • Given a set of parameters... • Build Model (service / repository) • Render Template with model given • and let other’s to figure out which template to render Wednesday, May 20, 15
  32. 32. Decorate / Exhibit Controller HTTP GET Domain View Exhibit 1) build model 2) render 3) exhibit View tmpl 4) render Wednesday, May 20, 15
  33. 33. How does it work Wednesday, May 20, 15
  34. 34. few design decision done by me • avoid nulls • separate Read Model from Write Model • 1st class collections • Separated Query and Command Controller (sort of CQRS) Wednesday, May 20, 15
  35. 35. Domain Entity: Group <if> ReadOrWriteModel <if> ReadModel <if> WriteModel GroupEntity GroupDescrGroupList Wednesday, May 20, 15
  36. 36. Domain Entity: Group <if> ReadOrWriteModel <if> ReadModel <if> WriteModel GroupEntity GroupDescrGroupList Wednesday, May 20, 15
  37. 37. Domain Entity: Group GroupEntity * immutable * final private prop * behavior rich GroupDescriptor * public properties * tiny behavior AGroupThatDoes NotExistYet AGroup Wednesday, May 20, 15
  38. 38. Domain Entity: Group <if> ReadOrWriteModel <if> ReadModel <if> WriteModel GroupEntity GroupDescrGroupList Wednesday, May 20, 15
  39. 39. Domain Entity: Group GroupList * behavior: iterate Wednesday, May 20, 15
  40. 40. Introducing Exhibits • Introduced by Avdi Grimm • sort of presenter-decorator Wednesday, May 20, 15
  41. 41. Exhibit Characteristics • Wraps a single model instance • Is a true Decorator • Brings together model and context • Encapsulates the decision about how to render an object • May modify the behavior of an object Wednesday, May 20, 15
  42. 42. Exhibit B Exhibit A Exhibit visually Model object Wednesday, May 20, 15
  43. 43. Exhibits: Group <if> Exhibit + renderBody() GroupListExh GroupList GroupExhibit GroupEntity EditGroupExh GroupDesc GroupWPicture Wednesday, May 20, 15
  44. 44. Exhibits: Group GroupListExh ListView GroupExhibit ShowGroup EditGroupExh GroupDesc GroupWPicture ShowGPicture Wednesday, May 20, 15
  45. 45. REST view HTTP PATH Contr#Action Domain Class GET /foo(.:format) foos#index FooList POST /foo(.:format) foos#create FooDescriptor GET /foo/new foos#new FooDescriptor GET /foo/:id/edit foos#edit FooDescriptor GET /foo/:id foos#show FooEntry PATCH/PUT /foo/:id foos#update FooDescriptor DELETE /foo/:id foos#delete FooDescriptor Wednesday, May 20, 15
  46. 46. Creating exhibits public exhibit(ReadWriteModel model){ for_each( exhibit: exhibit_classes ){ if( exhibit.applicableTo( model ) // wrap model to exhibit and serve exhibit as new model } } Wednesday, May 20, 15
  47. 47. Creating exhibits the ruby way 1/2 Avdi Grimm: Object on Rails, Listing 77 Wednesday, May 20, 15
  48. 48. Creating exhibits the ruby way 2/2 Avdi Grimm: Object on Rails, Listing 77 Wednesday, May 20, 15
  49. 49. Creating exhibits the Java 8 way 1/N Wednesday, May 20, 15
  50. 50. Time for some code Confluence plugin Velocity templates Wednesday, May 20, 15
  51. 51. View Wednesday, May 20, 15
  52. 52. Controller Wednesday, May 20, 15
  53. 53. Exhibit A Wednesday, May 20, 15
  54. 54. Exhibit B Wednesday, May 20, 15
  55. 55. Exhibit C Wednesday, May 20, 15
  56. 56. Exhibit D Wednesday, May 20, 15
  57. 57. And visually Wednesday, May 20, 15
  58. 58. Surroundings Exhibit templates Wednesday, May 20, 15
  59. 59. RemotePictureExhibit || DefaultPictureExhibit UserProfileExhibit Could be composite Wednesday, May 20, 15
  60. 60. Did it work - in retrospect • No issues in production with this code • It is not, by far, easy to grasp. Without someone explaining Wednesday, May 20, 15
  61. 61. What I did not show • transformations of domain entities: • Request -> Write -> Persistence • Persistence -> Write (-> Read) • Composite Exhibit - how to show 0, 1 or many concepts, dynamically, based on the ModelObject rendered Wednesday, May 20, 15
  62. 62. What could I experiment • Capabilities for exhibits • Capability.mobile • Capability.REST • Capability.json Wednesday, May 20, 15
  63. 63. Thanks! Questions? skype: @rinkkasatiainen twitter: @rinkkasatiainen email: aki.salmi@iki.fi Wednesday, May 20, 15

×