Optimal marriage of pure logic and display classes

15 views
Skip to first unread message

Terrence Brannon

unread,
Mar 22, 2013, 3:50:51 PM3/22/13
to mun...@googlegroups.com

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.py

and a display engine:
https://github.com/metaperl/muntjac-clean-calc/blob/master/calc.py

But 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.


Reply all
Reply to author
Forward
0 new messages