Skip to content

Instantly share code, notes, and snippets.

@antklim
Last active November 10, 2020 03:12
Show Gist options
  • Select an option

  • Save antklim/53792f0a01dbedb943b10b02f084f556 to your computer and use it in GitHub Desktop.

Select an option

Save antklim/53792f0a01dbedb943b10b02f084f556 to your computer and use it in GitHub Desktop.
class CalculatorUseCase {
...
// callbacks to notify state changes
void Function() onMemoryChanged;
void Function() onOperationChanged;
CalculatorUseCase(
{Operation operation,
this.operandA = 0,
this.operandB = 0,
this.onMemoryChanged,
this.onOperationChanged}) {
this.operation = operation ?? Add;
}
...
void setOperation(Operation value) {
operation = value;
onOperationChanged?.call(); // notify state changes
}
void Function(num) setOperand(Operand operand) {
onOperationChanged?.call();
return (operand == Operand.A) ? _setOperandA : _setOperandB;
}
void memorise() {
memory = value;
onMemoryChanged?.call(); // notify state changes
}
void resetMemory() {
memory = null;
onMemoryChanged?.call(); // notify state changes
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment