Last active
November 10, 2020 03:12
-
-
Save antklim/53792f0a01dbedb943b10b02f084f556 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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