Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.48 KB | None | 0 0
  1. //
  2. // CHALLENGE (work in pairs):
  3. // Move from f(o) -> o.f()
  4. //
  5.  
  6.  
  7. // 1
  8. // Turn on object-thinking and re-design the code accordingly
  9. class CsvParser<T extends Line> {
  10. Collection<T> parse(File location) {
  11. }
  12. }
  13.  
  14.  
  15. // 2
  16. // Turn on object-thinking and re-design the code accordingly
  17. interface Pinger {
  18. void sendPing();
  19. }
  20.  
  21.  
  22. // 3
  23. // rename the method to improve readability
  24. interface Input {
  25. boolean validate();
  26. }
  27.  
  28. // 4
  29. // turn procedural code into object-oriented
  30. class MortgageRiskService {
  31.  
  32. BigDecimal calculateRisk(MortageApplication mortgageApplication) {
  33. ...
  34. }
  35.  
  36. boolean isTolerable(BigDecimal risk) {
  37. ...
  38. }
  39. boolean areRisksEquivalent(BigDecimal oneRisk, BigDecimal otherRisk) {
  40. ...
  41. }
  42. }
  43.  
  44. // 4.5
  45. // turn procedural code into object-oriented
  46. class BankruptcyProbabilityCalculator {
  47. BigDecimal calculate(Business business) { ... }
  48. }
  49. class BankruptcyProbabilityUtils {
  50. boolean isHigh(DecimalNumber decimal) { ... }
  51. }
  52.  
  53. // 5
  54. interface BlacklistingService {
  55. boolean shouldBlockWebsiteVisitor(BlacklistRequest request);
  56. }
  57.  
  58. interface BlacklistRequest {
  59. String getEmail();
  60. String getIpAddress();
  61. }
  62.  
  63.  
  64.  
  65.  
  66. // 6
  67. interface AnonymousUserAuthenticator {
  68. Token authenticate(String username, String password) throws WrongCredentialsException;
  69. }
  70.  
  71. // 7
  72. interface Suite {
  73. interface SuiteTest {
  74. void print();
  75. boolean successful()
  76. }
  77. void runAndWait();
  78. Collection<SuiteTest> listSuiteTests();
  79. }
  80.  
  81. suite.runAndWait()
  82. for (SuiteTest suiteTest : suite.listSuiteTests()) {
  83. if (!suiteTest.successful() ) {
  84. // pretty printing
  85. suiteTest.print();
  86. }
  87. }
  88.  
  89. // 8.1
  90. // What's the expected return type of the method (if you look at the code from the outside?)
  91. // If you didn't expect boolean (as most develoeprs), rename it so it's clear that the boolean is returned
  92. enum Severity {
  93. boolean major();
  94. }
  95.  
  96. // 8.2
  97. // What's the expected return type of the method (if you look at the code from the outside?)
  98. // If you didn't expect boolean (as most develoeprs), rename it so it's clear that the boolean is returned
  99. class Specification {
  100. boolean satisfiedBy(Entity entity);
  101. }
  102.  
  103.  
  104. // 9 SLAP!
  105. boolean destroyButtonAvailable =
  106. widgets
  107. .stream()
  108. .filter(Widget::isButton)
  109. .filter(button -> button.label().equals("Destroy The World"))
  110. .isPresent();
  111.  
  112.  
  113.  
  114. // 10 transform a full name into a twitter handle. Jack Ma must become @jack.ma
  115. String fullName = "Jack Ma";
  116. ...
  117. String twitterHandle =
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement