Designing for reusability – Apple WebObjects 3.5 User Manual

Page 106

Advertising
background image

Chapter 6

Creating Reusable Components

106

that were linked in to the application executable for a component with that
name. For example, applications written entirely in WebScript use the default
application executable,

WODefaultApp

. This executable is linked to the frameworks

WebObjects.framework

and

WOExtensions.framework

, so any components defined in either

of these two frameworks can be used in a scripted application.

Designing for Reusability

Here are some points to consider when creating reusable components:

Make sure that your reusable component generates HTML that can be
embedded in the HTML of its parent component.

A reusable component should be designed to be a “good citizen” within
the context in which it will be used. Thus, for example, the template file
for a reusable component should not start and end with the <HTML> and
</HTML> tags (since these tags will be supplied by the parent
component). Similarly, it is unlikely that a reusable component’s template
would contain <BODY>, <HEAD>, or <TITLE> tags.

Further, if you intend your component to be used within a form along with
other components, don’t declare the form (<FORM...> ... </FORM>)
within the reusable component’s template file. Instead, let the parent
component declare the form. Similar considerations pertain to submit
buttons. Since most browsers allow only one submit button within a form,
putting a submit button in a reusable component severely limits where it
can be used.

Guard against name conflicts.

Reusable components are identified by name only. See “Search Path for
Reusable Components” (page 105). Those that reside within a particular
application’s application directory are available only to that application.
Those that reside in a framework (for example,

WOExtensions.framework

) are

available to all applications that link to it. Suppose you have a component
named NavigationControl in your application and one of the frameworks
that your application links to also has a NavigationControl component.
Which one will be used in your application? The result is unpredictable.

Reusable component names need to be systemwide unique. Consider
adding a prefix to component names to increase the likelihood that they
will be unique.

Advertising