-
-
Save aivarsk/4d04c41d73b6605ddd371483abd899ee to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// CHALLENGE (work in pairs): | |
// Move from f(o) -> o.f() and sure that the code is CQS compliant. | |
// | |
// 1 | |
class CsvParser<T extends Lines> { | |
Collection<T> parse(File location) { | |
} | |
} | |
// 2 | |
interface Pinger { | |
void sendPing(); | |
} | |
// 3 | |
interface TcpSocket { | |
Stream<Byte> startReading(); | |
} | |
// 4 | |
// Make me CQS friendly! | |
interface Input { | |
boolean validate(); | |
} | |
// 5 | |
// Iovation - a company that maintains a blacklist of email addresses and corresponding IPs | |
interface IovationService { | |
boolean shouldBlockWebsiteVisitor(IovationClientRequest request); | |
} | |
interface IovationClientRequest { | |
String getEmail(); | |
String getIpAddress(); | |
} | |
// 6 | |
interface AnonymousUserAuthenticator { | |
Token authenticate(String username, String password) throws WrongAuthenticationCredentialsProvided; | |
} | |
// 7 | |
interface Test { | |
interface TestResult { | |
void print(); | |
} | |
boolean over(); | |
Collection<TestResult> listTestResults(); | |
} | |
if (test.over()) { | |
for (TestResult tr : test.listTestResults()) { | |
// pretty printing | |
tr.print(); | |
} | |
} | |
// 8 | |
// Booleans are queries, but exception to the CQR rule naming. They are not nouns. Let's fix it (guess how). | |
enum Severity { | |
boolean major(); | |
} | |
class Specification { | |
boolean satisfiedBy(Entity entity); | |
} | |
// 9 | |
boolean destroyButtonAvailable = | |
widgets | |
.stream() | |
.filter(Widget::isButton) | |
.filter(button -> button.label().equals("Destroy The World")) | |
.isPresent(); | |
// 10 | |
interface File { | |
void openAndThrowIfNotFound(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment