Line: 1 to 1 | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
Deleted: | ||||||||
< < | Paper outline
Goal: eliminate crosscutting of widgets; one aspect per widget instance
| |||||||
Using Aspects to build GUIs | ||||||||
Added: | ||||||||
> > | Sukesh Chopra, Kaitlin Duck Sherwood, and Sebastian Streg | |||||||
Using traditional Object-Oriented programming techniques, code for building a GUI becomes tangled: layout code becomes tangled with behavior code. For example, consider a simple GUI with one button and one label, where the the label displays the number of times that the button has been pushed. When creating the label, the developer has to specify not only the visual aspects of the label, but also keep a pointer to the label that the button can use. When creating the button, the developer has to specify not only the visual aspects, but also define the behavior that the button should take when it is pushed. Our goal in this project is to separate out the visual description from the behavioural description. We want to allow users to write | ||||||||
Line: 61 to 52 | ||||||||
Instead, we realized that since we had to use a wrapper anyway, we could pass an instance identifier to a wrapper's constructor and use that id in advice to determine whether it was the correct instance for that advice. In the case of widgets with behaviour (e.g. "execute foo() when this button is pushed", the behaviour is attached to the widget once, right after construction of the widget. In cases where the widget has state that needs to be maintained, a pointer to the widget can be grabbed once, right after construction of the widget. | ||||||||
Added: | ||||||||
> > | @@@ example code?
Unmodified, Swix takes as inputs
| |||||||
Status | ||||||||
Added: | ||||||||
> > | We lost a huge amount of time trying to configure Eclipse to get load time weaving to work, so are a bit behind. (We are not the only group bitten by configuration issues; Arjun also spent a lot of time configuring Eclipse.) We plan to modify Swix so that instead of making JComponent instances, it makes calls to our wrapper classes. At this point, it makes XButton, XTextField, and XLabel instances instead of JButton, JTextField, and JLabel instances. | |||||||
References |
Line: 1 to 1 | ||||||||
---|---|---|---|---|---|---|---|---|
Added: | ||||||||
> > |
Using Aspects to build GUIsUsing traditional Object-Oriented programming techniques, code for building a GUI becomes tangled: layout code becomes tangled with behavior code. For example, consider a simple GUI with one button and one label, where the the label displays the number of times that the button has been pushed. When creating the label, the developer has to specify not only the visual aspects of the label, but also keep a pointer to the label that the button can use. When creating the button, the developer has to specify not only the visual aspects, but also define the behavior that the button should take when it is pushed. Our goal in this project is to separate out the visual description from the behavioural description. We want to allow users to write
Tool selectionWe had two decisions to make about tools: what language to use and what tools to aid us in translating from XML to GUI. We decided very quickly to use AspectJ. "Working on the bleeding edge" is a euphemism for "all the tools break", and we felt that it would be far safer to use a language with significant in-house expertise than one that did not. Thus we did not consider languages like AspectWerkz, CAESER, or EOS. We found a number of tools that took XML as input and either generated Java as output or displayed a GUI:
Approaches consideredThere were two main issues we needed find solutions for.
Load-time weavingWe attempted weave the Swing widgets at load time. We spent a huge amount of time trying to configure the tools, with no success. The documentation that exists for AspectJ with Java 5 is not entirely helpful. The official docs are reference materials and seem to be aimed at people who already understand the material. We found very few sites with tutorials and/or example code, and the best load-time weaving example[Vasseur2004] that we found was out of date. Furthermore, we found a reference [Xerox200?] that said that load time reweaving of the java.* and javax.* classes was not possible. (We theorize that it is not allowed for security reasons.) We thus decided that discretion was the better part of valor, and instead put wrapper classes around the Swing widgets.Instance-level aspectsWe considered several solutions for instance-level aspects. One thing we considered was to make a different class for each instance, with each class subclassed from the "true" class. For example, we could have e.g. JButtonFahrenheitButton and JButtonCelsiusButton both be subclasses of JButton. This looked ugly: we would need to programmatically generate the wrapper classes on the fly; in order to write the aspects properly, the developer would need to understand that dummy classes were being built with ugly names. Similarly, we considered inserting a dummy method in the wrapper class(es) to correspond to each instance. The only function of the dummy methods would be to give the developer something unique to the instance that they could then exploit with a pointcut. Instead, we realized that since we had to use a wrapper anyway, we could pass an instance identifier to a wrapper's constructor and use that id in advice to determine whether it was the correct instance for that advice. In the case of widgets with behaviour (e.g. "execute foo() when this button is pushed", the behaviour is attached to the widget once, right after construction of the widget. In cases where the widget has state that needs to be maintained, a pointer to the widget can be grabbed once, right after construction of the widget.StatusReferences[Vasseur2004] Alex Vasseur, Load-time weaving with AspectJ 1.2, The Aspect Blog, May 29, 2004, http://www.aspectprogrammer.org/blogs/adrian/2004/05/loadtime_weavin.html![]() ![]() |