Skip to content

Instantly share code, notes, and snippets.

@joshiraez
Created January 1, 2020 03:55
Show Gist options
  • Save joshiraez/4dc08f3d25f5ea002182f60cfe5c1a38 to your computer and use it in GitHub Desktop.
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.
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