1
I ntroduction to Programming – Lecture 23 1 Chair of Softw are EngineeringIntroduction to Programming Bertrand Meyer
Last revised 13 January 2005
I ntroduction to Programming – Lecture 23 2 Chair of Softw are EngineeringLecture 23: An example: undo-redo
I ntroduction to Programming – Lecture 23 3 Chair of Softw are EngineeringThe problem
Enabling users of an interactive system to cancel the effect of the last command. Often implemented as “Control-Z”. Should support multi-level undo-redo, with no limitation other than a possible maximum set by the user A good review of O-O techniques
I ntroduction to Programming – Lecture 23 4 Chair of Softw are EngineeringWorking example: text editor
Notion of “current line”. Assume commands such as: Insert line after current position Insert line before current position Delete current line Replace current line Swap current line with next if any ... This is a line-oriented view for simplicity, but the discussion applies to more sophisticated views
I ntroduction to Programming – Lecture 23 5 Chair of Softw are EngineeringUnderlying class (from “business model”)
class EDIT_CONTROLLER feature text: LI NKED_LIST [ STRING] remove is
- - Remove line at current position.
require not off do text.remove end put_right (line: STRI NG) is
- - Insert line after current position.
require not after do text.put_right (line) end ... end
I ntroduction to Programming – Lecture 23 6 Chair of Softw are EngineeringKey step in devising a software architecture Here: The notion of “command”
Finding the right abstractions
(Interesting object types)