Table of Contents Previous Section

Simplifying Interfaces

Another benefit of reusable components is that they let you work at a higher level of abstraction than would be possible by working directly with HTML code or with WebObjects' dynamic elements. You (or someone else) can create a component that encapsulates a solution to a possibly complicated programming problem, and then reuse that solution again and again without having to be concerned with the details of its implementation. Examples of this kind of component include:

To illustrate this feature, consider a simple reusable component, an alert panel:

Figure 2. Alert Panel

The panel is similar to the navigation table introduced above, but as you'll see, most of the component's attributes are customizable.

To use this component, you simply declare its position within the HTML page and give it a name:

<HTML>
<HEAD>
    <TITLE>Alert</TITLE>
</HEAD>
<BODY>
<WEBOBJECT NAME = "ALERT"></WEBOBJECT>
</BODY>
</HTML>

The declarations file specifies the value for each of the panel's attributes, either by assigning a constant value or by binding the attributes value to a value determined by the script file (as with the alertString and infoString attributes below):

ALERT: AlertPanel {
    alertString = alertTitle;
    alertFontColor = "#A00000";
    alertFontSize = 6;
    infoString = alertDescription;
    infoFontSize = 4;
    infoFontColor = "#500000";
    tableWidth = "50%";
};

The script file defines the alertTitle and alertDescription methods, which return the text that's displayed in the upper and lower panes of the alert panel. The alertDescription method could, for example, consult a database to determine the release date of the video.

The AlertPanel reusable component is one of several components included in the Reusable Components Examples. If you take a look at the source code for AlertPanel, you'll notice that it's moderately complicated and in fact relies on other reusable components for its implementation. However, WebObjects lets you think of the AlertPanel component as a black box. You simply position the component in your HTML template, specify its attributes in the declarations file, and implement any associated dynamic behavior in the script file.

Table of Contents Next Section