Sharing reusable components across applications – Apple WebObjects 3.5 User Manual
Page 104
Chapter 6
Creating Reusable Components
104
For instance, it’s sufficient in the example shown in Figure 31 to simply
declare a
childValue
instance variable in the child component and a
parentValue
instance variable in the parent. You need to implement accessor methods
(such as
setChildValue:
and
childValue
) only if the component must do some
calculation (say, determine how long the application has been running)
before returning the value.
•
If you do provide accessor methods, they should have no unwanted side
effects and should be implemented as efficiently as possible since they will
be invoked several times in a request-response loop cycle.
•
If you bind a component’s attribute to a method rather than to an instance
variable, you must provide both accessor methods: one to set the value and
one to return it.
Let’s say the parent component in the example shown in Figure 31 doesn’t
have a discrete
parentValue
instance variable but instead stores the value in
some other way (for example, as an entry in a dictionary object). In that
case, the parent component must provide both a
parentValue
method (to
retrieve the value) and a
setParentValue:
method (to set it). During
synchronization, WebObjects expects both methods to be present and will
raise an exception if one is missing.
Sharing Reusable Components Across Applications
If a component is in the WebObjects application’s directory, it can be used over
and over again, but only within that application. This may be fine for some
components, but others, you’ll want the option to reuse in many applications. If
a component is packaged in a framework, it can be used in any WebObjects
application.
To package components in a framework for reuse by several applications, do the
following:
1. Create a project in Project Builder of type WebObjectsFramework.
2. Add to this project (under Web Components) all of the components that you
want to share across applications.
3. Add any resources needed by the components. If the HTTP server needs
access to the resource (which is the case for image files and any file that will
ultimately be referenced in the HTML file), add it under
WebServerResources. Otherwise, add it under Resources.