Case Study Designing A Telephone Directory Program Ellen

  • Slides: 20
Download presentation
Case Study: Designing A Telephone Directory Program Ellen Walker CPSC 201 Data Structures Hiram

Case Study: Designing A Telephone Directory Program Ellen Walker CPSC 201 Data Structures Hiram College Includes figures from Objects, Abstraction & Data Structures in Java v. 5. 0, by Koffman & Wolfgang, Wiley © 2005

The Problem • Client wants to store a simple telephone directory in her computer

The Problem • Client wants to store a simple telephone directory in her computer • Use for storage & retrieval of names & numbers • Create from existing data file • Insert new names & numbers • Change numbers • Retrieve numbers • Save in data file

Requirements: Inputs & Outputs • Inputs – File: one name & number per line

Requirements: Inputs & Outputs • Inputs – File: one name & number per line – Interactive: name & number when requested • Outputs – Name(s) & number(s) - one per line – File: complete directory in sequence (same format as input file)

Analysis • Use Case – List user actions and system responses for a particular

Analysis • Use Case – List user actions and system responses for a particular subproblem (case) as they occur • For the Phone Directory 1. 2. 3. 4. Read directory from existing file Insert new entry Edit existing entry Retrieve and display entry

Read Directory From File • 1. User issues command to load & run directory

Read Directory From File • 1. User issues command to load & run directory • 2. System starts program, initializing directory from data file. If the data file does not exist, an initially empty data file is created.

Insert New Entry / Edit Entry 1. 2. 3. 4. 5. 6. User issues

Insert New Entry / Edit Entry 1. 2. 3. 4. 5. 6. User issues insert or edit command System prompts for name User enters name (If canceled, terminate) System prompts for number User enters number (If canceled, terminate) Directory is updated with new name/number (user is informed whether new entry is added or entry was changed; if changed both old and new numbers are shown)

Retrieve Entry

Retrieve Entry

Initial Design (subproblems)

Initial Design (subproblems)

Class Diagram (initial)

Class Diagram (initial)

Class Diagram (Revised) PDApplication + main() <<interface>> PDUser. Interface process. Commands() PDGUI PDConsole <<interface>>

Class Diagram (Revised) PDApplication + main() <<interface>> PDUser. Interface process. Commands() PDGUI PDConsole <<interface>> Phone. Directory. Interface load. Data() add. Or. Change. Entry() lookup. Entry() … Array. Lists. Based. PD + load. Data() + add. Or. Change. Entry() +lookup. Entry() … Directory. Entry - String name - String number + get. Name() + get. Number() …

List of Classes • PDUser. Interface - interacts with the user • PDApplication -

List of Classes • PDUser. Interface - interacts with the user • PDApplication - contains main, instantiates everything else • Phone. Directory. Interface - the interface for a phone directory • Array. List. Based. PD - an implementation of that interface • Directory. Entry - a name/number pair

PDApplication • One Method, main – Create a new Phone. Directory object – Send

PDApplication • One Method, main – Create a new Phone. Directory object – Send it a message to read the initial directory data from a file – Create a new PDUser. Interface Object – Send it a message to perform all user operations on the Phone. Directory object • This method will set up a loop that accepts and executes commands (using internal methods)

Directory. Entry Class

Directory. Entry Class

Phone. Directory Interface

Phone. Directory Interface

Array. Based PD implements Phone. Directory

Array. Based PD implements Phone. Directory

Class structure

Class structure

Implementing and Testing the Array. Based Phone Directory

Implementing and Testing the Array. Based Phone Directory

Implementing and Testing the Array. Based Phone Directory (continued) • Note that some code

Implementing and Testing the Array. Based Phone Directory (continued) • Note that some code in this application is controversial – Combination of assignment with the evaluation of a condition – Break statement allows exiting of the while loop without storing an entry

Controversial Code

Controversial Code

Implementations of PDUser. Interface • PDGUI (graphical) • PDConsole. UI (text-based)

Implementations of PDUser. Interface • PDGUI (graphical) • PDConsole. UI (text-based)