Created
January 1, 2020 03:55
-
-
Save joshiraez/4dc08f3d25f5ea002182f60cfe5c1a38 to your computer and use it in GitHub Desktop.
Third example for "Rethinking interfaces". Now making totally equivalent our "interface class" to implement our interface.
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
class OperationInterfaceAsClass implements Operation { | |
Predicate<String> isOperation; | |
Function<List<Integer>, Integer> operate; | |
private OperationInterfaceAsClass(){}; | |
public static OperationInterfaceAsClass of( | |
Predicate<String> isOperation, | |
Function<List<Integer>, Integer> operate | |
){ | |
OperationInterfaceAsClass toBuild = new OperationInterfaceAsClass(); | |
toBuild.isOperation = isOperation; | |
toBuild.operate = operate; | |
return toBuild; | |
} | |
@Override | |
public boolean isOperation(final String input) { | |
return this.isOperation.test(input); | |
} | |
@Override | |
public int operate(final List<Integer> numbers) { | |
return this.operate.apply(numbers); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment