Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // CHALLENGE (work in pairs):
- // Move from f(o) -> o.f()
- //
- // 1
- // Turn on object-thinking and re-design the code accordingly
- class CsvParser<T extends Line> {
- Collection<T> parse(File location) {
- }
- }
- // 2
- // Turn on object-thinking and re-design the code accordingly
- interface Pinger {
- void sendPing();
- }
- // 3
- // rename the method to improve readability
- interface Input {
- boolean validate();
- }
- // 4
- // turn procedural code into object-oriented
- class MortgageRiskService {
- BigDecimal calculateRisk(MortageApplication mortgageApplication) {
- ...
- }
- boolean isTolerable(BigDecimal risk) {
- ...
- }
- boolean areRisksEquivalent(BigDecimal oneRisk, BigDecimal otherRisk) {
- ...
- }
- }
- // 4.5
- // turn procedural code into object-oriented
- class BankruptcyProbabilityCalculator {
- BigDecimal calculate(Business business) { ... }
- }
- class BankruptcyProbabilityUtils {
- boolean isHigh(DecimalNumber decimal) { ... }
- }
- // 5
- interface BlacklistingService {
- boolean shouldBlockWebsiteVisitor(BlacklistRequest request);
- }
- interface BlacklistRequest {
- String getEmail();
- String getIpAddress();
- }
- // 6
- interface AnonymousUserAuthenticator {
- Token authenticate(String username, String password) throws WrongCredentialsException;
- }
- // 7
- interface Suite {
- interface SuiteTest {
- void print();
- boolean successful()
- }
- void runAndWait();
- Collection<SuiteTest> listSuiteTests();
- }
- suite.runAndWait()
- for (SuiteTest suiteTest : suite.listSuiteTests()) {
- if (!suiteTest.successful() ) {
- // pretty printing
- suiteTest.print();
- }
- }
- // 8.1
- // What's the expected return type of the method (if you look at the code from the outside?)
- // If you didn't expect boolean (as most develoeprs), rename it so it's clear that the boolean is returned
- enum Severity {
- boolean major();
- }
- // 8.2
- // What's the expected return type of the method (if you look at the code from the outside?)
- // If you didn't expect boolean (as most develoeprs), rename it so it's clear that the boolean is returned
- class Specification {
- boolean satisfiedBy(Entity entity);
- }
- // 9 SLAP!
- boolean destroyButtonAvailable =
- widgets
- .stream()
- .filter(Widget::isButton)
- .filter(button -> button.label().equals("Destroy The World"))
- .isPresent();
- // 10 transform a full name into a twitter handle. Jack Ma must become @jack.ma
- String fullName = "Jack Ma";
- ...
- String twitterHandle =
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement