code_junkie

Fluent interfaces and leaky abstractions

Nov 13th, 2011
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. Find.All.Questions(Where.IsAnswered == true);
  2.  
  3. m_Window = window::with()
  4. .width(l_Width)
  5. .height(l_Height)
  6. .title("default window")
  7. .left(200)
  8. .top(200)
  9. .create();
  10.  
  11. ::CreateWindow(
  12. "Window class",
  13. "Window title",
  14. dwStyle, X, Y,
  15. nWidth, nHeight,
  16. hWndPant, hMenu,
  17. hInstance, NULL
  18. );
  19.  
  20. public interface NotFluent
  21. {
  22. void DoA();
  23. void DoB();
  24. void DoC();
  25. }
  26.  
  27. public interface Fluent
  28. {
  29. Fluent DoA();
  30. Fluent DoB();
  31. Fluent DoC();
  32. }
  33.  
  34. NotFluent foo = new NotFluentImpl();
  35. foo.DoA();
  36. foo.DoB();
  37. foo.DoC();
  38.  
  39. Fluent bar = new FluentImpl();
  40. bar.DoA().DoB().DoC();
  41.  
  42. public City GetCity(string zipCode)
  43. {
  44. zipCode.Assert("zipCode").IsNotNullOrEmpty().HasLength(5,10).Matches("\d[5]-\d[4]");
  45. // Continue processing
  46. }
  47.  
  48. Car car = new CarImpl();
  49. MarketingDescription des = new MarketingDescriptionImpl();
  50. desc.setType("Box");
  51. desc.setSubtype("Insulated");
  52. desc.setAttribute("length", "50.5");
  53. desc.setAttribute("ladder", "yes");
  54. desc.setAttribute("lining type", "cork");
  55. car.setDescription(desc);
  56.  
  57. Car car = Car.describedAs()
  58. .box()
  59. .length(50.5)
  60. .type(Type.INSULATED)
  61. .includes(Equipment.LADDER)
  62. .lining(Lining.CORK);
Add Comment
Please, Sign In to add comment