[an error occurred while processing this directive]
[an error occurred while processing this directive]

AC3: UI Software Architecture

The goal of this activity is to explore the main structuring patterns of GUI software: the view hierarchy, the observer pattern, and model-view-controller.

1 The View Hierarchy of Firefox

This exercise requires Mozilla Firefox, with the DOM Inspector installed.

One of the neat features of Firefox is its DOM Inspector, which allows you to browse through the Document Object Model (DOM) of a web page. The DOM is a tree corresponding to the parsed HTML of the web page. It is, in fact, a view hierarchy (plus some other stuff thrown in that usually doesn't appear in view hierarchies in other GUI toolkits, such as script code and comments).

Visit a web page and pop up the DOM Inspector.. Use Ctrl-Shift-I or Tools/DOM Inspector to pop it up. Drill down into the BODY element and click around a little. Notice that when you select a node in the Inspector, its bounding box in the web page is highlighted with a flashing red border. That shows you the area of the screen covered by that view.

Even cooler, the Firefox DOM Inspector can also display the view hierarchy for the whole Firefox window, not just the web page it's showing. In the Inspector, use File/Inspect a Window to inspect the whole browser window whose web page you were just looking at. Drill down into window, and find the statusbar element near the end of the list. Click on statusbar, and you should see it highlighted in the browser window.

Here are a few things to explore:

What are the container elements? What are the primitive elements? Primitive elements are actually hard to find! Even a node like a textbox or a label, which in other toolkits would be a leaf of the view hierarchy, appears to have children. What do you think is going on here?

2 Model-View-Controller

Design models (identifying key methods and events) for these user interfaces:

The last case is somewhat interesting, because the dialog box may need nothing but standard widgets -- textboxes, listboxes, checkboxes, etc. -- which are already tiny MVC patterns. So do we need a separate model representing a person for this interface? Can't the person be represented implicitly, by the values stored in all those widgets? Sometimes yes, sometimes no. Think about the tradeoffs.

3 An MVC Example

Address Book

This exercise uses the simple AddressBook program shown on the right. (Note that this is by no means a usable address book interface. We're more interested in the software architecture than in the interface design for this exercise.)

Run AddressBook.jar, and explore its source code to answer the questions below.

4 Observer Pattern Pitfalls

Event-based programming can be tricky. This exercise explores some of the pitfalls by asking you to find bugs in a feature of the AddressBook program.

Run the AddressBook, and press Add several times to add blank entries to the address book. Press List to get back to the list. The Cleanup button is supposed to remove all these blank entries, but when you press it, it only removes one entry and then throws an exception. (To see the exception, run the jar from your command prompt.)

Explore the three implementations of the Cleanup button found in AddressBook.java:

[an error occurred while processing this directive]