Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // 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) {
- // }
- // }
- class Csv <T>{
- Collection<T extends Lines> content(File f);
- }
- class CsvFile<T extends Lines>{
- public CsvFile(Path path);
- Collection<T> lines();
- //or return stream -> this means lazy and read only
- }
- // 2
- interface Ping {
- void send();
- }
- or Endpoint{ (or antyhing)
- void ping();
- }
- // 3
- interface TcpSocket {
- Stream<Byte> read(); //verb so should return void
- Stream<Byte> stream(); // ok
- }
- // 4
- // Iovation - a company that maintains a blacklist of email addresses and corresponding IPs
- interface IovationClientRequest {
- String getEmail();
- String getIpAddress();
- boolean blockAccess();
- }
- this way:
- interface IovationService {
- boolean shouldBlockWebsiteVisitor(WebsiteVisitor wv)
- }
- interFACE WebsiteVisitor {
- String email();
- String ipAddress();
- }
- // 5
- interface User{
- String username, password;
- Token authenticate() throws WrongUserCredentialsProvided
- }
- this way:
- interface Authentication{
- Authentication (String username, String password);
- Token token();
- void attempt();
- }
- auth = new Authentication(...)
- auth.token();
- // 6
- interface Test {
- interface Result {
- void prettyPrint();
- }
- boolean hasFinished();
- Collection<Test.Result> results();
- }
- if (test.finished()) {
- //refactor into stream
- //test.results().forEach(Test.Result""prettyPrint)
- for (Test.Result testResult : test.results()) {
- testResult.prettyPrint();
- }
- }
- // 7
- boolean destroyButtonAvailable =
- widgets
- .stream()
- .filter(Widget::isButton)
- .filter(Buttonlabel::isRedButton)
- OR
- map Button::label
- filter "Destory the world"::equals
- OR anyMatch instead of filter
- .isPresent();
- class Buttonlabel implements Predicate<Button>{
- public static boolean isRedButton (Button b){
- return b.label().equals("Destroy The World");
- }
- }
- // 8
- interface File {
- void openIfFound();
- }
Add Comment
Please, Sign In to add comment