Design Problem #1
Folded File Viewer Internal Representation

Context

It is desired to build a folded file viewer (also called an outline viewer or a holophrastic display). A folded file viewer allows its users to view the contents of a text file while possibly hiding details. For example, if the file being viewed contained some source code, then initially, the viewer might display the file as follows.



Now the user might decide to collapse part of the text (say the Preheating case) and insert a summarizing comment in its place. After this operation is performed, the display might look like the following.



The user might now continue by collapsing the entire switch statement. This might leave the display looking like the following.



Still later, or during another session, the user could expand one of the collapsed items to view its details. After viewing the details, the user might choose to recollapse, restoring the previous view.

Problem Statement

Imagine that you had to design such a tool. In particular, your job was to devise an internal representation that could remember collapses and expansions. For example, initially your representation would have to contain information about each of the 29 lines (including blank lines), including its textual contents and the fact that no collapses had yet been performed.

After the first collapse, the representation should indicate that the display has three parts (ten lines of text, a collapsed segment including its descriptive comment, and the remaining nine lines of text). The collapsed segment has to contain the missing ten lines of text. That is, there are now two levels in the representation: the visible contents and the hidden segment. After the second collapse, another level must be added to the representation. {It looks like some form of tree structure is called for.} Finally, when the expand is performed, the representation must somehow indicate that the viewable contents should look like the second window above, while remembering the state that existed when the third window obtained.

Think about how you would design such an internal representation. In particular, either by yourself or with others, produce a simple UML class model diagram that is sufficient to model the internal state of the tool.

Notes