Developing a Mini Calculator Part -4

Hello, this is the final part of article on Developing a Mini Calculator. Here we will see how different modules interact with each other and the importance of central module called “Core” in detail.

About Core module in detail

As I mentioned in the previous topics this module is most important part of our calculator application, because it maintain the application state and do connect other modules with each other using messaging system. Input service, output service, calculation logic and history recorder send message to and receive message from core module. Core module do the state change using the messages received from input service and calculation logic.

How Core and other modules work together ?

Input Service generate message based on the key pressed by the user and send the message to core module. The message will have identifier to identify the message, key details. Core will process the message, do some state change and send required messages based on the state change to other modules. Below I will give you a example simple scenario.c

Example: “65+56=”

So once user press “=” operator key calculator should display result “121”.

  1. User enter key 6: This will send message to core module. It will be store as first operand
  2. User enter key 5: Since no operator is entered, core will append “5” to previously entered number “6” and make “65” the first operand
  3. User enter “+” operator key: When processing this key press, core will do a state  that tell operator is entered now it will accept the second operand. If user press any other operator key to change the operation, this will be taken care by core module using the previous state change.
  4. The same way “56” will be accepted
  5. Now core have first operand, operator and second operand. If user press the next operator key (-,+,*,/), core will send a message to calculation logic including this details. Calculation logic do the required calculation and send back the result to core.
  6. The result given by calculation logic will be the new first operand. The same can be treated as final result as well based on the past input.
  7. In the above steps, core will send the state changes to output service. Output service will display the state changes received to screen.

THE END

Hope you liked the final part 🙂 .

Please access the previous topics here
Developing a Mini Calculator Part – 1
Developing a Mini Calculator Part – 2
Developing a Mini Calculator Part – 3

Advertisements