[Dev] User Interface
David Hyatt
hyatt at apple.com
Fri Nov 8 17:06:37 PST 2002
Curt Hibbs wrote:
>
> The are some additional drawbacks to XUL that aren't apparent until
you have
> developed a significant XUL code-base. I spent a year and half
developing a
> very large, commercial application based on XUL. Initially, XUL
seemed to be
> a very attractive solution (and I believe that it still is for small
> applications). However, the way that the behavior of an XUL
application is
> mixed with UI layout specification makes it very challenging to
maintain
> clean, understandable code. Consequently, the level of development
effort
> was much higher than I had expected.
This is untrue. The behavior of a XUL application can be kept entirely
separate from the XML file that describes the layout of the user
interface. In fact you have numerous paths that you can follow to
achieve this separation.
While it is true that XUL supports the mixing of behavior and layout in
order to make it more accessible to HTML developers, that doesn't mean
you have to write your XUL files that way.
Here are some sample approaches that you could take to keep behavior
separate from the XML file.
(1) Use an external script file included from the XML document. This
script file could use the DOM addEventListener API to register JS
functions as listeners on the various elements. This keeps all of the
JS code out of the XML file.
(2) Do the same thing as (1), but in C++. Listeners could be attached
dynamically in response to the "load" event of the XUL document (or
earlier should you desire).
(3) Using stylesheets and XBL you can attach bindings to the elements
via CSS. Since XBL can specify event handlers, you could perform the
linkage this way. (This would allow you to use CSS's selector
mechanism to attach the same event handlers to whole classes of
elements).
(4) You could use dynamic overlays and hold your behavior in a separate
chrome package that can be dynamically superimposed onto the XUL
structure (or the overlay could just use scripts and follow an approach
similar to (1)).
There are plenty of easy solutions to this problem.
dave
(hyatt at apple.com)
More information about the Dev
mailing list