The interaction between all classes is as follows :
- I am a button. I can have one of three labels - ["increment", "decrement", and "reset"] and my action corresponds to whichever button is pressed. When I am pressed, I send a message to DivisorCount to do the labelled function.
- I am a DivisorCount. When I receive an increment message, I increment myself. If my Value is even, I send a message to EvenCount to increment. If my value is odd, I send a message to OddCount to increment. When I receive a decrement message, I decrement myself and send messages to OddCount and EvenCount to decrement. When I receive a reset message, I reset myself to 0 and send messages to OddCount and EvenCount to reset to 0 as well. I also broadcast a message to all my dependents that I have changed.
- I am a DisplayBox. I receive a message that a change hs occurred. I send a message bcak to the appropriate Count that I want the updated value. I display the updated value.
- [If the Value is Even : ] I am an EvenCount. I am an instance of IntegerCount. I receive a message to increment. I send a message to all my dependents that I have changed.
I am a SlaveDisplayBox. I receive a message that a change I am interested in has occurred. I send a message to EvenCount to send me the updated value. I display the updated value.
- [If the Value is Odd : ] I am an OddCount. I am an instance of IntegerCount. I receive a message to increment. I send a message to all my dependents that I have changed.
I am a SlaveDisplayBox. I receive a message that a change I am interested in has occurred. I send a message to OddCount to send me the updated value. I display the updated value.
The program is run when DivisorCount new is typed. This means that everything should be able to be done after this is typed. This requires a new method which declares all variables and calls the boxes, as will be done in the programming part.
Initialization
DivisorCount and IntegerCount will be initialized to 0. When reset is invoked, all all of the values will be re-initialized to 0. Reset will work in such a way that it will be called by DivisorCount, which will send reset messages to oddCount and evenCount. The initialize function of DivisorCount will reset all these values when DivisorCount new is called.