Designing a Calculator in Java using Command Pattern (Low Level Design)
5 Entities
- Command Interface - to provide the structure a concrete command needs to implement.
- Concrete Command Implementation - implements Command Interface and provides for execute and unexecute methods. Also provides undo alternative for each operator (+ > -, - > +, * > /, / > *).
- Calculator - has a show value and also provides action for +,-,*,/.
- Invoker - basically the user, computes and undos on request. Keeps a Stack of Commands in case needed to undo.
- Calculator Test - driver of the code.