Design Pattern From Java To Ruby

1,467 views
1,408 views

Published on

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,467
On SlideShare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
28
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Design Pattern From Java To Ruby

  1. 1. Design Pattern -- from Java to Ruby Richard Ekohe www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  2. 2. Why use Design Pattern  For reuse www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  3. 3. Why use Design Pattern  For communication www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  4. 4. Why use Design Pattern Define a Node interface, all of leaf nodes and internal nodes should implements the interface, internal nodes has a list that  For communication includes other internal nodes and leaf nodes and it can add and remove sub-nodes. But leaf node can’t have add sub-node method. www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  5. 5. Why use Design Pattern Define a Node interface, all of leaf nodes and internal nodes should implements the interface, internal nodes has a list that  For communication includes other internal nodes and leaf nodes and it can add and remove sub-nodes. But leaf node can’t have add sub-node method. www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  6. 6. Why use Design Pattern Define a Node interface, all of leaf nodes and internal nodes should implements the interface, internal nodes has a list that  For communication includes other internal nodes and leaf nodes and it can add and remove sub-nodes. But leaf node can’t have add sub-node method. www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  7. 7. Why use Design Pattern  For communication www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  8. 8. Why use Design Pattern  For communication Composite Pattern www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  9. 9. Why use Design Pattern  For communication Composite Pattern www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  10. 10. Difference from java to ruby www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  11. 11. Difference from java to ruby  Classes are Objects www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  12. 12. Difference from java to ruby  Classes are Objects  Messages, not function call www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  13. 13. Difference from java to ruby  Classes are Objects  Messages, not function call  Duck Typing www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  14. 14. Difference from java to ruby  Classes are Objects  Messages, not function call  Duck Typing  Mixin www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  15. 15. Singleton Pattern  ensures a class has only one instance, and provides a global point of access to it www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  16. 16. Singleton Pattern www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  17. 17. Singleton Pattern You are my only wife www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  18. 18. Singleton Pattern You are my You are my only husband only wife www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  19. 19. Singleton Pattern -- java www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  20. 20. Singleton Pattern -- java  Eager loading www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  21. 21. Singleton Pattern -- java  Eager loading  Lazy loading www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  22. 22. Singleton Pattern -- ruby  Ruby built-in singleton www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  23. 23. Singleton Pattern -- ruby  Ruby built-in singleton www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  24. 24. www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  25. 25. www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  26. 26. www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  27. 27. www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  28. 28. www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  29. 29. Ruby for Design Pattern  Built-in (Singleton) www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  30. 30. Observer Pattern  defines a one-to-many dependency between objects so that when one object changes state, all of its dependents are notified and updated automatically www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  31. 31. Observer Pattern Subscribe Temperature Detector www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  32. 32. Observer Pattern Subscribe Temprature Temperature changed Detector www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  33. 33. Observer Pattern Notify Notify Subscribe Temprature Temperature changed Detector www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  34. 34. Observer Pattern -- java  Define interface by yourself www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  35. 35. Observer Pattern -- java  Define interface by yourself www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  36. 36. Observer Pattern -- java  Define interface by yourself www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  37. 37. Observer Pattern -- java  Define interface by yourself www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  38. 38. Observer Pattern -- java  Define interface by yourself www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  39. 39. Observer Pattern -- java  Define interface by yourself www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  40. 40. Observer Pattern -- java  Java built-in observer www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  41. 41. Observer Pattern -- java  Java built-in observer www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  42. 42. Observer Pattern -- ruby  Ruby built-in observer www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  43. 43. Observer Pattern -- ruby  Ruby built-in observer www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  44. 44. Observer Pattern -- ruby  Ruby built-in observer www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  45. 45. www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  46. 46. www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  47. 47. www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  48. 48. Ruby for Design Pattern  Built-in (Singleton, Observer)  Mixin www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  49. 49. Iterator Pattern  provides a way to access the elements of an aggregate object sequentially without exposing its underlying representation www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  50. 50. Iterator Pattern Count 1 2 3 10 www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  51. 51. Iterator Pattern -- java  Java built-in Iterator and mock Iterator www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Merb - Offshore Web Development
  52. 52. Iterator Pattern -- java  Java built-in Iterator and mock Iterator www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Merb - Offshore Web Development
  53. 53. Iterator Pattern -- java  Java built-in Iterator and mock Iterator www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Merb - Offshore Web Development
  54. 54. Iterator Pattern -- java  Java built-in Iterator and mock Iterator www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Merb - Offshore Web Development
  55. 55. Iterator Pattern -- ruby  Nothing, just .each www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  56. 56. Iterator Pattern -- ruby  Nothing, just .each www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  57. 57. Iterator Pattern -- ruby  Nothing, just .each www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  58. 58. Ruby for Design Pattern  Built-in (Singleton, Observer, Iterator)  Mixin www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  59. 59. Simple Factory Pattern  returns an instance of one of several possible classes, depending on the data provided to it. www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  60. 60. Simple Factory Pattern www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  61. 61. Simple Factory Pattern -- java  Compare with String, a lot of if/else www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  62. 62. Simple Factory Pattern -- java  Compare with String, a lot of if/else www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  63. 63. Simple Factory Pattern -- java  Compare with String, a lot of if/else www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  64. 64. Simple Factory Pattern -- java  Compare with String, a lot of if/else www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  65. 65. Simple Factory Pattern -- java  Compare with String, a lot of if/else www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  66. 66. Simple Factory Pattern -- java  Compare with String, a lot of if/else www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  67. 67. Simple Factory Pattern -- ruby  Classes are Objects www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  68. 68. Simple Factory Pattern -- ruby  Classes are Objects www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  69. 69. Simple Factory Pattern -- ruby  Classes are Objects www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  70. 70. Simple Factory Pattern -- ruby  Classes are Objects www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  71. 71. Ruby for Design Pattern  Built-in (Singleton, Observer, Iterator)‫‏‬  Mixin  Classes are Objects www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  72. 72. Command Pattern  encapsulates a request as an object, thereby letting you parameterize clients with different requests, queue or log requests, and support undoable operations. www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  73. 73. Command Pattern www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  74. 74. Command Pattern -- java www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  75. 75. Command Pattern -- java www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  76. 76. Command Pattern -- java www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  77. 77. Command Pattern -- java www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  78. 78. Command Pattern -- java www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  79. 79. Command Pattern -- ruby  Proc www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  80. 80. Command Pattern -- ruby  Proc www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  81. 81. Ruby for Design Pattern  Built-in (Singleton, Observer, Iterator)‫‏‬  Mixin  Classes are Objects  Proc www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  82. 82. Other Design Patterns Make use of ruby advantage www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  83. 83. Ruby's Principle www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  84. 84. Ruby's Principle  DRY – Don't Repeat Yourself www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  85. 85. Ruby's Principle  DRY – Don't Repeat Yourself  Convention Over Configuration www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  86. 86. Resources  Design Pattern – Elements of Reusable Object-Oriented Software Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides  Head First Design Pattern Kathy Sierra, Bert Bates  Design Pattern in Ruby Russ Olsen www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
  87. 87. Q&A happy to discuss and fix my mistakes www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development

×