This tutorial consists of exercises on the visitor pattern discussed in class. It also helps prepare for homework 03.
The UMLclass diagram below models keys and cars using the visitor pattern. Though AKey is depicted here as an abstract class, it can also be an interface.
You are to do the following:
1. Fill in the concrete methods of all the above concrete classes so that only a specific key will drive a specific car when that car's turnKey() method is called with that key, i.e. call its drive() method. All other keys will call the car's alarm() method.
For instance, suppose we have:
- An object called ford of type Ford, and
- An object called fordKey of type FordKey
then ford.turnKey(fordKey) will cause ford.drive() to be called.
On the other hand, suppose instead we have
- An object called saturnKey of type SaturnKey
then ford.turnKey(saturnKey) will cause ford.alarm() to be called.
2. Fill in the ACar.drive() and ACar.alarm() methods to print out something indicative that the method has been called, e.g. "Car has been driven!" and "Car alarm sounded!".
3. Document your code, of course. It is recommended that you document the methods before you write the method bodies! (Remember Comp210?)
3. Write a JUnit test class that clearly tests all possible key and car combinations. Be sure that the test methods print clear messages indicating exactly what is being tested at the moment, i.e. what key-car combination is being used.
Create the object system that models the following using the Visitor Design pattern:
You're sitting in your room...um...."working"....or maybe not..... Suddenly, the phone rings and some person is on the other end. You need to proffer a response, but the exact response behavior will depend on not only what you've been doing, but who the person on the line is.
Now, there are a couple of scenarios:
Some things to consider:
You are required to do the following:
Create a subdirectory called OOscheme. Click here to copy the (zipped up) OOscheme code to the OOscheme directory. Unzip the file.
You will need use the IList framework in the OOscheme package in order to compile and test your code. You must be in the parent directory of OOscheme to compile all of your code. Put all the visitors in the package OOscheme.visitor (a package visitor inside the package OOscheme).