Spreadsheet Graphs and MVC l Model View Controller

  • Slides: 4
Download presentation
Spreadsheet: Graphs and MVC l Model, View, Controller is MVC Ø Model stores and

Spreadsheet: Graphs and MVC l Model, View, Controller is MVC Ø Model stores and updates state of application • Example: calculator, what's the state of a GUI-calculator? Ø When model changes it notifies its views appropriately • Example: pressing a button on calculator, what happens? Ø The controller interprets commands, forwards them appropriately to model (usually not to view) • Example: code for calculator that reacts to button presses • Controller isn't always a separate class, often part of GUI-based view in M/VC l MVC is a fundamental design pattern: solution to a problem at a general level, not specific code per se Ø Patterns part of new foundation of object-orientation CPS 100 spreadsheet. 1

Spreadsheet Model and graphs l What happens when we enter a number, string, or

Spreadsheet Model and graphs l What happens when we enter a number, string, or formula? Ø Model changes to record new entry in a cell • Propagate change to views Ø Model changes to incorporate dependent calculations • What about D 10 change when B 10 changes below? l l Graphs: why? Controller? View? Dump command? CPS 100 spreadsheet. 2

Toward a working SSModel subclass l How can we associate expressions with cells? Ø

Toward a working SSModel subclass l How can we associate expressions with cells? Ø Effects of the command SET A 2 = SUM(B 1: B 10) Ø We need to get/set expressions, storage possibilities? Ø How do we notify views when change occurs? l How can we propagate changes to dependent cells? Ø What associations made for SET A 2 = SUM(B 1: B 10) ? • Edge from B 1 to A 2, why? • Edge from A 2 to B 1, why? • Given a graph, how do we propagate changes to model? Ø l Can we just call View: : set for every cell and every view? Use cell/row/col functions in util. h for help with model code CPS 100 spreadsheet. 3

Handling exceptions l How can we handle unanticipated, but certain to occur errors? Ø

Handling exceptions l How can we handle unanticipated, but certain to occur errors? Ø Consider command SET A 2 = AVERG(B 5: B 1) Ø Ø Errors can occur deep in parsing code (recursive) Where should error be handled? l C++ and Java use exceptions to indicate exceptional condition. Ø Errors indicated by throwing exception Ø Client code catches the exception (or program aborts) Ø Client try/catch blocks guard against uncaught exceptions l Exceptions in spreadsheet are runtime_error objects Ø Catch pointer, report using re->what() string CPS 100 spreadsheet. 4