The only additions that cannot be directly devised from the static object
structure are the each-other containment relationships between Heading
and Link ; these relationships have been added based on knowledge of the
All containment relationships in this class diagram are ordered because
the order in which contained elements appear in the container element is
important (e.g. the heading of a section should appear before the text that
constitutes its content).
Class Page does not contain any specific information. Class Head contains
only the title of the HTML page (i.e. Test in the example above). Class Body
contains the background colour, which is encoded in the bgcolor parameter
inside the <body> tag. Class Text contains the fragment of text it represents.
Class Heading contains the text that constitutes the heading. Finally class
Link contains the destination URL of the hyperlink. In addition, all classes
except Head and Text can contain other elements that are linked to them.
We try now to refine the analysis model described so far. First we identify
commonalities among different classes and factor them into a common base
class connected to the specific classes by inheritance. This is an application
of the class generalization idiom presented in Chapter 6. Three main
characteristics can be identified as common to the elements of the analysis
1 Most elements have a string associated with them, which represents the
content of the element or some other parameter. The information asso-
ciated with the various elements may be very different; the common
characteristic is that it can be stored in a string. Examples of such
information are the background colour of the tag body, or the text that
constitutes a document fragment.
2 All elements must provide an opening tag and a closing one.
3 Most elements must provide mechanisms to iterate on the contained
elements for exploring the page elements and for serializing the page
The main differences among these elements are related to the mechanisms
used to iterate on the document structure. Each class must provide specific
methods for accessing its content; for instance class Page should provide a
method for accessing the Head component and another method for accessing
its Body component.
Document elements must implement iteration mechanisms.