1
A set of classes and interfaces for an action adventure game is given below. Among these classes,
you will find classes for game characters (e.g. Queen, King, Knight, Troll) and also classes for
weapon behaviours the characters can use in the game. Each character can make use of one weapon
at a time, but can change weapons at any time during the time.
a)
Select the most appropriate design pattern to use to address the above situation.
b) Arrange the classes and draw appropriate relationships between classes.
c) To switch weapons, each character calls the setWeapon() method, put the method setWeapon()
into the right class.
void setWeapon(WeaponBehavior w) {
this.weapon = w;
}

2
Answer:
a)
Strategy pattern.
b)
To switch weapons, each character calls the setWeapon() method, which is defined in the
Character superclass.

3
Consider an object-oriented design of a simple searching system. The system employs several
searching algorithms such as LinearSearch, BinarySearch. The clients of this system should be able
to use different searching algorithm at different times.

