The interface for this spreadsheet is intended to be a view only interface so that the user can see the :

  1. Type of formula the spreadsheet is using
  2. The values being used to calculate the net value
  3. The net value as calculated by value method.

Another important feature of the interaction component should be its ability to automatically update dependent spreadsheets. That implies the need for a dependency database. We also need to make sure that the view object created (the actual window) should update on a change in the spreadsheet.

To implement all the above we use the following messages:

Dependency tracking

The dependency can be automatically tracked by making the spreadsheets a sub-class of Model. All Models have an instance variable called dependents which is a DependentsCollection and the Model implementation makes sure that all the dependents are sent the update: message with the symbol representing the change as a parameter. (All of this is in Model so I don't need to draw diagrams for it but I am describing it here).

The way the system works is simple. Every Model can transmit a 'You have changed' message to any other object by the changed: method passing a symbol as a parameter denoting what has changed. The Model takes care of this message by saying to all dependents of the receiver (as defined by the dependents instance variable) to update: themselves with the same symbol denoting what to update. So every dependent object is automatically taken care of by the Model implementation if the dependents instance variable is correctly kept updated.

To do this, every specialized spreadsheet that uses the values from another spreadsheet calls a addme: method passing itself as a parameter. The receiver adds the object into the dependents variable thus making sure.that the Model will correctly handle all updates.

Also every specialized spreadsheet now understand a useful update: method. We have to make sure that every object knows how to update itself So what every spreadsheet does on receiving a update: message is call changed: with self thus telling itself, 'I have changed, make sure every of my dependents is updated too. So the change& and update: messages ripple through the chain of dependents eventually reaching the last spreadsheet in line which is dependent on no other spreadsheets.

Every view object (known as a SpreadSheetViewContainer) is also included in the dependency database so the windows know when to change. They have their own special update: methods so they can get new values to display. This SpreadSheetViewContainer is described next.

SpreadSheetViewContainer Class:

This is a Container class which is a subclass of ModelCollectionViewContainer. ModelCollectionViewContainer embodies all the 'dirty work' that goes into the handling of update: messages. Simply we can describe it as being able to perform a redraw on a reception of an update: message. It also knows how to get new data from the spreadsheet that it is connected to. (We actually tell it when we create it).

The SpreadSheetViewContainer Class just over-rides certain methods which are used to create the view. It creates a view with a list box and a display box to display a list of objects and another object(s) separately in the display box. It also redefines the size of the window when initially created.

The Spreadsheet classes also make sure that the views are created at the same time when the actual spreadsheet objects are created. This they do by creating a new instance of the SpreadSheetViewContainer and initilializing it so that it gets mentioned in the dependentscollection of the spreadsheet and that its update: method reflects the correct method names that would give the SpreadSheetViewContainer the data it needs to display.

So the net effect is:

  1. SpreadSheet class gets called with a creation method (any of the type...)
  2. SpreadSheet class calls a specific sub-class telling it to create a new instance and initialize it.
  3. SpreadSheet class calls SpreadSheetViewContainer and tells it to create a new instance and link that new instance to the newly created object.
  4. When the spreadsheet instance detects a update: method or changes any of its values it sends a changed: message to itself.
  5. When the spreadsheet instance detects a changed: method, it sends an update: to all the dependents in the dependents variable. (Inherited from Model).
  6. When a SpreadSheetViewContainer detects a update: method, it calls the spreadsheet that it is linked to, to get new information. Then it does a repaint with that data. (Inherited from ModelCollectionViewContainer). Inside SpreadSheetViewContainer we define the method to get the content of the list box as 'cells' and the contents of the resultant value display box as 'value'. We also have to make sure that every spreadsheet knows what to display in the list box. The specialized sub-classes of Spreadsheet class each have a cells method which returns a collection of the values of every cell in string fonnat so that the list box can display them one on each line in order. Every specialization of Spreadsheet class has its own way of dealing with this method since all the sub-classes hold different type of data.