Skip to content

Instantly share code, notes, and snippets.

@joshiraez
Created January 1, 2020 04:52
Show Gist options
  • Save joshiraez/bec9c60cb96e8cbde85f8f0f3472b924 to your computer and use it in GitHub Desktop.
Save joshiraez/bec9c60cb96e8cbde85f8f0f3472b924 to your computer and use it in GitHub Desktop.
How would you create classic instances using this aproach, creating a factory. "Rethinking interfaces"
class OperationWithOperationData {
Predicate<String> isOperation;
IntBinaryOperator reductionOperation;
List<Integer> toOperateOn;
private OperationWithOperationData() {};
public static Function<
List<Integer>,
OperationWithOperationData
> of(
Predicate<String> isOperation,
IntBinaryOperator reductionOperation
){
return toOperateOn ->
{
OperationWithOperationData toBuild = new OperationWithOperationData();
toBuild.isOperation = isOperation;
toBuild.reductionOperation = reductionOperation;
toBuild.toOperateOn = toOperateOn;
return toBuild;
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment