Lecture23 - A set of classes and interfaces for an action adventure game is given below Among these classes you will find classes for game

Lecture23 - A set of classes and interfaces for an action...

This preview shows page 1 - 4 out of 6 pages.

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; }
Image of page 1
2 Answer: a) Strategy pattern. b) To switch weapons, each character calls the setWeapon() method, which is defined in the Character superclass.
Image of page 2
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.
Image of page 3
Image of page 4

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture