I have rewritten the Muntjac calculator demo so that there is a pure
calculation engine:
https://github.com/metaperl/muntjac-clean-calc/blob/master/pure_calc.pyand a display engine:
https://github.com/metaperl/muntjac-clean-calc/blob/master/calc.pyBut the big question is: how do you optimally "marry" the two pure classes together?
Do you think there should be two different .buttonClick() listeners -
one for the digit operations and one for the other operations?
It wouldnt be impossible, but I wonder if it's overkill. It might look
like this:
class CalcButtonAction(IClickListener):
def buttonClick(self, e):
button = e.getButton()
requestedOperation = button.getCaption()[0]
self.pure_calc.proc_char(requestedOperation)
class CalcDigitButtonAction(CalcButtonAction):
def buttonClick(self, e):
super(CalcDigitButtonAction, self).buttonClick(e)
self._display.setValue(self.pure_calc._current)
class CalcOtherButtonAction(CalcButtonAction):
def buttonClick(self, e):
super(CalcDigitButtonAction, self).buttonClick(e)
self._display.setValue(self.pure_calc._stored)
But then we have repetition in the calls to .setValue().
Another approach would be decorators.
Any input is welcome.