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.

Talking About Fluent Interface

2,964 views

Published on

Published in: Technology
  • Be the first to comment

Talking About Fluent Interface

  1. 1. 2008‐11‐19(Wed); AppleStore, Sapporo Ruby Sapporo Night vol.8 Talking about “Fluent interface” snoozer.05@ruby‐sapporo.org Ruby /Ruby SHIMADA Koji; Nihon Ruby-no-kai; RubySapporo http://www.flickr.com/photos/mio-spr/2042538806
  2. 2. ✓ ✓ ✓ ✓ ✓
  3. 3. RubyConf 2008 http://rubyconf.org/
  4. 4. Neal Ford, Advanced DSL in Ruby http://www.nealford.com/downloads/conferences/canonical/Neal_Ford- Advanced_DSLs_in_Ruby-slides.pdf
  5. 5. Neal Ford, Advanced DSL in Ruby http://www.nealford.com/downloads/conferences/canonical/Neal_Ford- Advanced_DSLs_in_Ruby-slides.pdf
  6. 6. Neal Ford, Advanced DSL in Ruby http://www.nealford.com/downloads/conferences/canonical/Neal_Ford- Advanced_DSLs_in_Ruby-slides.pdf
  7. 7. ?
  8. 8. ✓ ✓
  9. 9. http://www.flickr.com/photos/quanle/251201209/
  10. 10. http://www.flickr.com/photos/jw3000/12703492
  11. 11. Martinfowler’s Biki http://capsctrl.que.jp/kdmsnr/wiki/bliki/?FluentInterface
  12. 12. Expect.Once.On(mockLogger) .Method(“LogError”) .With(Has.Substring(USER_NAME) & Has.Substring(“access defined”)); mainframe.expects(once()) .method(“buy”).with(eq(QUANTITY)) .will(returnValue(TICKET));
  13. 13. ✓ ✓ ✓
  14. 14. ?
  15. 15. http://www.flickr.com/photos/srijith/1867095482
  16. 16. ✓ ✓
  17. 17. ✓ ✓
  18. 18. http://www.flickr.com/photos/mdd/175282811
  19. 19. ✓ ✓
  20. 20. ✓ ✓
  21. 21. http://www.flickr.com/photos/ozyman/443545349
  22. 22. ✓ ✓
  23. 23. ✓ ✓
  24. 24. ✓ ✓ ✓
  25. 25. http://www.flickr.com/photos/fuckr/91530309
  26. 26.
  27. 27. Martinfowler’s Biki http://capsctrl.que.jp/kdmsnr/wiki/bliki/?FluentInterface
  28. 28. Evolving an EDSL in Java http://www.mockobjects.com/files/ evolving_an_edsl.ooplsa2006.pdf
  29. 29. ✓ ✓ ✓ http://www.flickr.com/photos/17258892@N05/2588347668
  30. 30. http://www.flickr.com/photos/good_day/117131491/
  31. 31. ✓ ✓ ✓
  32. 32. A B C b a c
  33. 33. tmp1 = data.grep(/foo/) tmp2 = tmp1.uniq tmp3 = tmp2.sort tmp4 = tmp3.join(“¥n”) tmp4.display data.grep(/foo/).uniq.sort.join(“¥n”).display
  34. 34. http://www.flickr.com/photos/jacky83/2311687241
  35. 35. ✓ ✓ ✓ ✓
  36. 36. Transcript clear. Transcript nextPutAll: ‘SHIMADA Koji’. Transcript cr. Transcript flush. Transcript clear; nextPutAll: ‘SHIMADA Koji’; cr; flush
  37. 37. A b a c
  38. 38. ✓ ✓ ✓
  39. 39. expectation.setCount(once()); expectation.setMethod(“buy”); expectation.setArgument(eq(QUANTITY)); expectation.setResult(TICKET); expectation.setCount(once()) .setMethod(“buy”) .setArgument(eq(QUANTITY)); .setResult(TICKET);
  40. 40. http://www.flickr.com/photos/mio-spr/428995450
  41. 41. ✓ ✓ ✓
  42. 42. expectation.setCount(once()) .setMethod(“buy”) .setArgument(eq(QUANTITY)); .setResult(TICKET); mainframe.expects(once()) .method(“buy”).with(eq(QUANTITY)) .will(returnValue(TICKET));
  43. 43. data.grep(/foo/).uniq.sort.join(“¥n”).display (1..10).map{|i| i*i}.select{|i| i % 2 == 0}
  44. 44. data.grep(/foo/).uniq.sort.join(“¥n”).display (1..10).map{|i| i*i}.select{|i| i % 2 == 0} mainframe.expects(once()) .method(“buy”).with(eq(QUANTITY)) .will(returnValue(TICKET));
  45. 45. ✓ ✓ ✓ http://www.flickr.com/photos/17258892@N05/2588347668
  46. 46. ✓ ✓ ✓
  47. 47. rate = Discount.new rate.cash = 0.05 rate.membership = 0.02 rate.price = 0.01 product.apply_discount(rate)
  48. 48. product.apply( Discount.for. cash(0.05). membership(0.02). price(0.01) )
  49. 49. class Discount ... def Discount.for Discount.new end def cash(discount) @for_cash = discount self end end
  50. 50. class Discount ... def Discount.for Discount.new end def cash(discount) @for_cash = discount self end end
  51. 51. class Discount ... def Discount.for Discount.new end def cash(discount) @for_cash = discount self end end
  52. 52. class Product ... def apply(discount) @discount = discount end ... end
  53. 53. product.apply( Discount.for. cash(0.05). membership(0.02). price(0.01) )
  54. 54. ✓ ✓ ✓ ✓
  55. 55. http://www.flickr.com/photos/srijith/1867095482
  56. 56. ...a programmer’s job is too communicate with other programmers, not just a machine. Programming, then, is a human task done by humans for humans. Oh, and writing good code at the same time.
  57. 57. http://www.flickr.com/photos/suvcougar/
  58. 58. http://ja.wikipedia.org/wiki/%E5%8B%95%E7%B7%9A ✓ ✓ ✓
  59. 59. http://www.flickr.com/photos/storm-crypt/2280100565
  60. 60. ✓ ✓ ✓ ✓
  61. 61. http://www.flickr.com/photos/nibaq/1735007
  62. 62. ✓ ✓ ✓ ✓ ✓ ✓
  63. 63. ✓ ✓ ✓ ✓ ✓ ✓
  64. 64. http://www.flickr.com/photos/pedrosz/2287112249
  65. 65. 2008‐11‐19(Wed); AppleStore, Sapporo Ruby Sapporo Night vol.8 Talking about “Fluent interface” snoozer.05@ruby‐sapporo.org Ruby /Ruby SHIMADA Koji; Nihon Ruby-no-kai; RubySapporo http://www.flickr.com/photos/mio-spr/2042538806

×