Bruce Eckel's Thinking in C++, 2nd Ed Contents | Prev | Next

Exercises

  1. Using SingletonPattern.cpp as a starting point, create a class that manages a fixed number of its own objects.
  2. Create a minimal Observer-Observable design in two classes, without base classes and without the extra arguments in Observer.h and the member functions in Observable.h. Just create the bare minimum in the two classes, then demonstrate your design by creating one Observable and many Observers, and cause the Observable to update the Observers.
  3. Change InnerClassIdiom.cpp so that Outer uses multiple inheritance instead of the inner class idiom.
  4. Add a class Plastic to TrashVisitor.cpp.
  5. Add a class Plastic to DynaTrash.cpp.
  6. Explain how AbstractFactory.cpp demonstrates Double Dispatching and the Factory Method .
  7. Create a business-modeling environment with three types of Inhabitant: Dwarf (for engineers), Elf (for marketers) and Troll (for managers). Now create a class called Project that creates the different inhabitants and causes them to interact( ) with each other using multiple dispatching.
  8. Modify the above example to make the interactions more detailed. Each Inhabitant can randomly produce a Weapon using getWeapon( ) : a Dwarf uses Jargon or Play, an Elf uses InventFeature or SellImaginaryProduct, and a Troll uses Edict and Schedule. You must decide which weapons “win” and “lose” in each interaction (as in PaperScissorsRock.cpp). Add a battle( ) member function to Project that takes two Inhabitants and matches them against each other. Now create a meeting( ) member function for Project that creates groups of Dwarf, Elf and Manager and battles the groups against each other until only members of one group are left standing. These are the “winners.”
Contents | Prev | Next


Contact: webmaster@codeguru.com
CodeGuru - the website for developers.
[an error occurred while processing this directive]