Chapter 13
|
Modified: |
Chapter 13 discusses how to analyze and design solutions - that is, determine the classes and methods. One approach, CRC cards, is examined.
Often the hardest part of developing a computer solution is analyzing the problem and designing a solution. There are many different approaches to problem solving but analysis and design often represent the first two steps to solving a complex problem. The following lists a common sequence:
There are six main steps to the Program Development Cycle:
- Analyze : Define the problem.
- Design: Plan the solution to the problem.
- Choose the interface: Determine how the program user will provide input and receive output.
- Code: Translate the algorithm into a programming language.
- Test and Debug: Locate and correct any errors.
- Complete the documentation: Organize all the material that describes the program.
nouns - ticket machines, tictactoe, clocks etc. correspond to classes.
verbs - play, get price, print ticket, etc. correspond to methods.
Analyze by describing the problem then marking nouns and verbs (nouns underlined, verbs in bold):
- The cinema booking system should store seat bookings for multiple theatres.
- Each theatre has seats arranged in rows.
- Customers can reserve seats, and are given a row number and seat number.
- They may request bookings of several adjoining seats.
- Each booking is for a particular show (that is, the screening of a given movie at a certain).
- Shows are at an assigned date and time, and scheduled in a theatre where they are screened.
- The system stores the customer's telephone number.
Exercise 1 - Discovering classes
Gin Rummy The game uses a standard deck of 52 cards. There are two to four players. The deck is shuffled. The dealer deals five cards to each player. The game prints the cards of each player.
- Underline the nouns.
- Circle the verbs.
Exercise 2 - Discovering classes
- What are obvious classes.
- What are obvious methods for those classes.
Exercise 3 - Writing classes
- Give the fields for some of the classes.
- Give the constructor for some of the classes.
- Give some methods.