Developing a Mini Calculator Part-3

Hello, this is third part of Developing a Mini Calculator. Today’s topic will cover Input Service and Output service module. Please read Developing a Mini Calculator Part-2 for understanding about Calculation logic.

Input Service

Like I said in the first section, input service is responsible for two things and they are accepting right input and preventing user from entering an input that may cause application behavior inconsistent. Input service alone can take some decisions for preventing user inputs. But sometimes it is not possible and that decision making require application state.

Consider an example scenario “user pressing period or dot key”. I will explain how the decision making works

How input service alone take decisions?

  • When application start input service will unlock period key
  • If user press period key input service will lock the period key
  • When user press period key it will send a message to core module saying user pressed period key

How input service take decision with the help of core module

  • When user press backspace key after pressing period key, input service will send a message to core module. Core module will understand that user pressed backspace key and so do a state change and send back a message to input service. So by identifying this message from core, input service can enable or unlock the period key.

Output Service

Output service is responsible for managing the screen and doing this by showing allowed application state to the screen. Output service will do this with the help of core, because core manage the application state.

Consider an example scenario “user entering number ‘6.’ and press backspace key to delete the dot character”

Hitting backspace key will initiate a message from input service to core. Core do the necessary state change and send a message to input service. After this core will send a message to output service  to delete the dot character from screen.

Advantages

  • Once messages are defined we can use it uniquely across all modules
  • Each module can be managed independently
  • Since communication across modules are achieved using messages, so maintenance is easy

 

Here ends the third session on mini calculator development. Hope you liked it 🙂 . In next topic I will explain about core module and communication between different modules using messages 🙂

Advertisements