Skip to topic | Skip to bottom


AMR.Commandsr1.1 - 29 Apr 2005 - 16:09 - MariusMarin

Start of topic | Skip to actions

Crosscutting Concerns implemented by the Command classes in JHotDraw


JHotDraw makes use of the Command design pattern in order to separate the user interface from the underlying model, and in order to support such features as undoing and redoing user commands. Each command has to realize the Command interface, for which a default implementation is provided in the AbstractCommand class. The key method is execute, which takes care of actually carrying out the command (such as pasting text, inserting an image into a drawing, etc.).

The Contract Enforcement instance

Each execute method, in the named, non-abstract command classes should start with a consistency check verifying that the underlying “view” exists. Therefore, each concrete implementation of execute starts with a call to the execute implementation in the superclass, which is always the one from the AbstractCommand.

Aspect Solution for the Contract Enforcement instance

The refactoring aims at removing duplication arising from statements that are common to the start of all method overrides of the execute superclass method. We implemented the Contract Enforcement instance using a pointcut to capture all execute methods and putting the check itself in the advice. It turns out that anonymous subclasses of AbstractCommand do not implement the consistency check. Such classes are used for simple commands such as printing, saving, and exiting the application. Since AspectJ does not provide a direct way to exclude anonymous classes in a pointcut, we used the within operator to exclude executions occurring in the context of the top level object creating the full user interface.

Testing Strategy

You are here: AMR > AJHotDraw > AJHotDrawReleasePlan > Commands

to top

Copyright © 2003-2017, Software Engineering Research Group, Delft University of Technology, The Netherlands