Tutorial 4: StructureBuilder, Visitor Pattern
Introduction
This tutorial covers:
- Evaluating arithmetic expressions using the Visitor Pattern (see Dr. Cartwright's
lecture notes)
- Using StructureBuilder to design class struture and generate stub codes.
I. Visitor Pattern for Evaluating Arithmetic Expressions
Here are the same grammar rules as in tutorial #3. We will use the visitor
pattern to evaluate arithmetic expression objects instead.
- ArithExpression ::= ConstExpression | SumExpression | ProdExpression | NegExpression
- ConstExpression ::= int
- SumExpression ::= ArithExpresssion '+' ArithExpresssion
- ProdExpression ::= ArithExpression '*' ArithExpression
- NegExpression ::= '-' ArithExpression
Here is the UML specification.
Exercises:
- Implement (i.e. write Java code) for each of the classes in the UML diagram as
specified. Use StructureBuilder to design the class structure. Your labbies
will show you how to use StructureBuilder. solutions
- Write test code to test your design solution (the solution contains very incomplete test
code).
II. StructureBuilder
- Run: /usr/site/sb/StructureBuilder
- Create class diagram page: File/New/Class diagram menu, or new Class diagram button
- Add a class: File/New/Class menu, or new class button; double-click on class diagram (or
right-click on Properties) to edit class name and select the appropriate directory to save
the class code.
- Save All menu : select the appropriate directory.
- Add fields and methods to classes: double-click on the class and use the properties
windows.
- Add subclasses: drag the inheritance arrow (the middle one) from the subclass to the
superclass.
- Create inerfaces: File/New/Interface menu, or new interface button.
- Add implementation classes and generate method stubs: drag the inheritance arrow
(the middle one) from a class to the interface; select the dotted arrow that represents
"implementation", right-click on it, and select Generate Method Stubs menu item.
D. X. Nguyen, Sept. 26, 1999.
dxnguyen@cs.rice.edu