The Object-Oriented Design Process

cs151

Chapter Topics

From Problem to Code

Three Phases:
Case Study: Voice Mail System

Analysis Phase

Functional Specification

Design Phase

Goals
Artifacts

Implementation Phase

Object and Class Concepts

Identifying Classes

Rule of thumb: Look for nouns (in singluar form) in problem description

Identifying Classes

Focus on concepts, not implementation

Categories of Classes

Identifying Responsibilities

Rule of thumb: Look for verbs in problem description

Behavior of MessageQueue:

Responsibilities

Class Relationships

Dependency Relationship ("uses")

Coupling

public class Message
{
public void print() { System.out.println(text); }
. . .
} The Message class is coupled with both the System and the PrintStream classes.

Aggregation ("has-a")

Multiplicities

Inheritance

Use Cases

Sample Use Case

Leave a Message

  1. Caller dials main number of voice mail system
  2. System speaks prompt
    Enter mailbox number followed by #
  3. User types extension number
  4. System speaks
    You have reached mailbox xxxx. Please leave a message now
  5. Caller speaks message
  6. Caller hangs up
  7. System places message in mailbox

Sample Use Case -- Variations

Variation #1

1.1. In step 3, user enters invalid extension number
1.2. Voice mail system speaks
     You have typed an invalid mailbox number.
1.3. Continue with step 2.

Variation #2

2.1. After step 4, caller hangs up instead of speaking message
2.3. Voice mail system discards empty message

CRC Cards

CRC Cards


CRC Cards

Walkthroughs

Walkthroughs

.


UML Diagrams

Class Diagrams

Class Diagrams

.

Class Relationships

.

Multiplicities

.

Composition

.

Association

.

Association

.

Interface Types

.

Tips

Sequence Diagrams

,


Self call


.

Object Construction

.

State Diagram

.

Design Documentation

Case Study: Voice Mail System

Use Case: Reach an Extension

  1. User dials main number of system
  2. System speaks prompt
    Enter mailbox number followed by #
  3. User types extension number
  4. System speaks
    You have reached mailbox xxxx. Please leave a message now

Use Case: Leave a Message

  1. Caller carries out Reach an Extension
  2. Caller speaks message
  3. Caller hangs up
  4. System places message in mailbox

Use Case: Log in

  1. Mailbox owner carries out Reach an Extension
  2. Mailbox owner types password and #
    (Default password = mailbox number. To change, see Change the Passcode)
  3. System plays mailbox menu:
    Enter 1 to retrieve your messages.
    Enter 2 to change your passcode.
    Enter 3 to change your greeting.

Use Case: Retrieve Messages

  1. Mailbox owner carries out Log in
  2. Mailbox owner selects "retrieve messages" menu option
  3. System plays message menu:
    Press 1 to listen to the current message
    Press 2 to delete the current message
    Press 3 to save the current message
    Press 4 to return to the mailbox menu
  4. Mailbox owner selects "listen to current message"
  5. System plays current new message, or, if no more new messages, current old message.
    Note: Message is played, not removed from queue
  6. System plays message menu
  7. User selects "delete current message". Message is removed.
  8. Continue with step 3.

Use Case: Retrieve Messages

Variation #1

1.1. Start at Step 6
1.2. User selects "save current message".
       Message is removed from new queue and appended to old queue
1.3. Continue with step 3.

Use Case: Change the Greeting

  1. Mailbox owner carries out Log in
  2. Mailbox owner selects "change greeting" menu option
  3. Mailbox owner speaks new greeting
  4. Mailbox owner presses #
  5. System sets new greeting

Use Case: Change the Greeting

Variation #1: Hang up before confirmation

1.1. Start at step 3.
1.2. Mailbox owner hangs up.
1.3. System keeps old greeting.

Use Case: Change the Passcode

  1. Mailbox owner carries out Log in
  2. Mailbox owner selects "change passcode" menu option
  3. Mailbox owner dials new passcode
  4. Mailbox owner presses #
  5. System sets new passcode

Use Case: Change the Passcode

Variation #1: Hang up before confirmation

1.1. Start at step 3.
1.2. Mailbox owner hangs up.
1.3. System keeps old passcode.

CRC Cards for Voice Mail System

Some obvious classes

Initial CRC Cards: Mailbox

.

Initial CRC Cards: MessageQueue

.

Initial CRC Cards: MailSystem

.

Telephone

Telephone

.

Connection

Connection

.

Analyze Use Case: Leave a message

  1. User dials extension. Telephone sends number to Connection
    (Add collaborator Connection to Telephone)
  2. Connection asks MailSystem to find matching Mailbox
  3. Connection asks Mailbox for greeting
    (Add responsibility "manage greeting" to Mailbox,
    add collaborator Mailbox to Connection)
  4. Connection asks Telephone to play greeting
  5. User speaks message. Telephone asks Connection to record it.
    (Add responsibility "record voice input" to Connection)
  6. User hangs up. Telephone notifies Connection.
  7. Connection constructs Message
    (Add card for Message class,
    add collaborator  Message to Connection)
  8. Connection adds Message to Mailbox

Result of Use Case Analysis

.

Result of Use Case Analysis

.

Result of Use Case Analysis

.

Result of Use Case Analysis

.

Analyse Use Case: Retrieve messages

  1. User types in passcode. Telephone notifies Connection
  2. Connection asks Mailbox to check passcode.
    (Add responsibility "manage passcode" to Mailbox)
  3. Connection sets current mailbox and asks Telephone to speak menu
  4. User selects "retrieve messages". Telephone passes key to Connection
  5. Connection asks Telephone to speak menu
  6. User selects "listen to current message". Telephone passes key to Connection
  7. Connection gets first message from current mailbox.
    (Add "retrieve messages" to responsibility of Mailbox).
    Connection asks Telephone to speak message
  8. Connection asks Telephone to speak menu
  9. User selects "save current message". Telephone passes key to Connection
  10. Connection tells Mailbox to save message
    (Modify responsibility of Mailbox to "retrieve,save,delete messages")
  11. Connection asks Telephone to speak menu

Result of Use Case Analysis

.

CRC Summary

UML Class Diagram for Mail System

Dependency Relationships

.

Aggregation Relationships

UML Class Diagram for Voice Mail System

.

Sequence Diagram for Use Case: Leave  a message

.

Interpreting a Sequence Diagram

Sequence Diagram for Use Case: Retrieve messages

.

Connection State Diagram

.

Java Implementation