Define a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically.
In this prototype, we build a simplest version. No Gui observer, no spreadsheet subject, no text interface for changing the state of subject. But the frame of observer pattern is there. It consists of:
In prototype 1, the spreadsheet class is added so that a spreadsheetsubject instance can have a single spreadsheet instance. The spreadsheet class is also an aggregate of Data objects. With slight modification of spreadsheetsubject class, we can have our prototype 2. Run it as prototype 1, we can get the same result.
In this prototype, we build our own simple text-interface. To run source code, simple issue the command: python txtinterface.py. The running result would look like this.
In this prototype, we change the spreadsheetobserver into a real spreadsheeetobserver. In this real spreadsheetobserver, user can specify any part of the spreadsheet to plot as long as it is in the range of the spreadsheet which is referenced by the spreadsheetsubject. With a slight modification of txtinterface.py. the runing result of source code would be like this.
In this prototype, we change the plotobserver into a real plotobserver. In this real plotobserver, user can specify any one column, one row, or two consecutive column or rows for plotting. With a slight modification of txtinterface.py. the runing result of source code would be like this.
In this prototype, we build a more powerful text interface. As you may noticed in the source code, the setState() of spreadsheetsubject and spreadsheet classes are also changed to that stated in UML class diagram.