CS 303E Lecture 19: Designing Classes - PowerPoint PPT Presentation

1 / 11
About This Presentation
Title:

CS 303E Lecture 19: Designing Classes

Description:

A problem analysis provides requirements of the program. ... Design Another Program. Design a program to play solitaire. Nouns / Classes. Verbs / Methods? ... – PowerPoint PPT presentation

Number of Views:113
Avg rating:3.0/5.0
Slides: 12
Provided by: MikeS2
Category:

less

Transcript and Presenter's Notes

Title: CS 303E Lecture 19: Designing Classes


1
CS 303E Lecture 19Designing Classes
It's supposed to be hard! If it wasn't hard,
everyone would do it. The hard... is what makes
it great! - Jimmy Dugan, A League of their Own
2
How are Complex Programs Designed?
  • A problem analysis provides requirements of the
    program.
  • In an object oriented design the object is King!
  • The purpose of the design phase is to discover
    the classes necessary to meet the requirements.
  • Important methods in a class are also discovered
    during design.

3
Design Classes for a Connect Four Program
  • Connect four is a game with two players.
  • Each player takes turns dropping a checker into
    one of 7 slots.
  • The checkers fall down to the bottom most
    available row in that column. (6 rows per
    column)
  • The first player to get 4 checkers in a row,
    vertically, horizontally, or diagonally wins.
  • thinks.com/java/connect4/connect4.htm

4
Requirements
  • Create a program that allows two people to play
    Connect Four on the computer.
  • The player playing black always goes first.
  • The computer determines a winner or if the game
    has resulted in a tie and announces this
  • Player may replay after each game
  • Players may concede a game

5
Starting the Design
  • Look for nouns in the requirements.
  • nouns normally are used to create classes?
  • Look for verbs
  • verbs normally are used to create methods in a
    class
  • What nouns / classes are there in connect four?
  • What verbs are there in connect four?

6
Who Does What???
  • Initial design results in many classes and
    methods
  • It may not be clear which class is responsible
    for each method
  • A CRC card is created for each class.
  • classes, responsibility, and collaborators card
  • An index card with the name of the class at the
    top.
  • index card so as to limit the number of methods
    in each class. Avoid large classes!

7
CRC Card
8
More on CRC Cards
  • CRC cards are a simple and informal tool used to
    design a program.
  • A collaborator is any class that helps accomplish
    the task or method
  • Several people can participate in design
  • each represents a few classes
  • role playing of classes to determine
    responsibilities and collaborators

9
Connect Four Classes
  • Player
  • Checker
  • Board
  • Display
  • And possibly others

10
Methods for Connect Four
  • Move / drop checker
  • Display board
  • Clear / reset board or game
  • Check for win
  • possibly others

11
Design Another Program
  • Design a program to play solitaire
  • Nouns / Classes
  • Verbs / Methods?
Write a Comment
User Comments (0)
About PowerShow.com