Exercise 4.1: OOA for a concert ticket site
Let's revisit the ticket-site example that was mentioned in Exercise 2.1. Here's the specification again.
A client can visit the server and search a schedule for a concert. A concert specifies a performer, a venue and a date. After selecting a concert, the client sees a list of some available tickets, specifying seat and price. The client can view a map to see where the seats are located. The client can select tickets and add them to his or her order. The client can buy the order by filling in an address form and giving credit card information.
Figure out a set of classes based on some or all of the nouns in the description and arrange them into a UML diagram. Test the completeness of your diagram by tracing some use cases through it. Draw the diagram at least three times, improving it each time.
Exercise 4.2: OOA for a music sharing site like the old Napster
A couple of years ago the music-sharing site called Napster ran a 'share-server' that satisfied the following specification. A client can log into the share-server. The share-server maintains a 'share pair list' of 'share pairs,' where a share pair consists of a song name and a link to a client who has this song available. When a client logs in, the share-server adds share pairs for the client's songs to the share pair list. A client can request a song, and the share-server displays a sublist of the share pair list showing share pairs for that song. If a client selects a share pair, the song is transferred to this client from the client mentioned in the share pair.
Figure out a set of classes based on some or all of the nouns in the description and arrange them into a UML diagram. The diagram will primarily have composition lines connecting the boxes. Test the completeness of your diagram by tracing some use cases through it. Draw the diagram at least three times, improving it each time.
Exercise 4.3: OOA for a music sharing site like KaZaA
Napster was successfully sued by the record companies for maintaining a share-server like this. In 2001 a possibly legal work-around emerged. Companies like KaZaA added another layer to the architecture. Rather than maintaining a share-server, they maintain a meta-server which directs clients to other client machines that are acting as share-servers.
Show how to add a meta-server to the UML diagram you got in the last exercise.
Exercise 4.4: Writing a utility class
Write a few lines of code to implement a utility container cCritterPair class to hold two cCritter * pointers as private members . The class should have a constructor that takes a pair of pointers as arguments and two accessors to get at the member pointers. Don't bother with mutators. Assume that cCritterPair should not delete its members in its destructor.
Exercise 4.5: Tweaking static variable values in the Spacewar game
Here we make some changes to the initializations of the static variables in gamespacewar.cpp and see what happens. When you change a static, it's usually wise to leave the original value as a comment to the right so you can get it back if necessary.
Increase cGameSpacewar::WORLDSIZE and notice how much bigger the world gets relative to the critters.
Increase cCritterAsteroid::DARTACCELERATION and cCritterAsteroid: :DARTSPEEDUP and notice that it becomes nearly impossible to shoot an asteroid .
Change cGameSpacewar::ASTEROIDHEALTH to four and notice how many times you have to shoot and split up an asteroid before finally getting rid of it.
Exercise 4.6: Composition and inheritance
Draw two pictures to represent the inheritance and composition relationships shown in Figure 4.8, but have your pictures represent classes by egg-shaped images as were used in Figure 4.5.