Professional Documents
Culture Documents
Design (Components Are Designed)
Design (Components Are Designed)
Design (Components Are Designed)
1
The Software Specification Challenge
2
The Software Life Cycle The Life and
Death of Software
Software products go through several stages as they
mature from initial concept to finished product
The sequence of stages is called a life cycle
3
Software Life Cycle Models
4
Waterfall Model
5
Software Life Cycle Models
6
Software Life Cycle Activities
1) Requirements 4) Test
Specification a. Unit Test
2) Design b. Integration Test
a. Architectural Design c. Acceptance Test
b. Component Design 5) Installation
c. Detailed Design 6) Maintenance
3) Implementation
7
Design Principles in Software Life Cycle
Activities
Top-down approach: breaking a system into a set of
smaller subsystems
Object-oriented approach: identification of a set of
objects and specification of their interactions
UML diagrams are a design tool to illustrate the
interactions between
Classes
Classes and external entities
8
Requirements Analysis, Use Cases, and
Sequence Diagrams
First step in analysis is to study the problem of input and
output requirements carefully to make sure they are
understood and make sense
Use case: list of the user actions and system responses
for a particular sub-problem in the order that they are
likely to occur
Sequence diagram: shows all the objects involved in
this use case across the horizontal axis, time is shown
along the vertical axis
9
Pre- and Postconditions
10
Using Abstraction to Manage Complexity
11
Using Abstraction to Manage Complexity
(contd)
Data abstraction: specify the data objects for a
problem and the operations to be performed on them
without concern for their representation in memory
Representation of a data object is irrelevant to other
classes that access to it only via its methods
Information hiding: concealing the details of a class
implementation from users of the class
12
An Example: Telephone Directory
13
Dependencies Among Possible Actions
14
Object Relations
15
Things you already know (about) ...
16
Interfaces
17
Interfaces
18
Public Methods of PhoneDirectory Interface
Method Action
public void loadData(String fileName) Loads the data from the data file whose name
is given by fileName
public String addOrChangeEntry(String name, Changes the number of the individual with the
String number) name to the number
public String lookupEntry(String name) Searches the directory for the name
public String removeEntry(String name) Removes the entry with the given name
public void saveData(String fileName) Saves the data in a load-able format in the
data file whose name is given by fileName
19
The PDUserInterface Interface
20
PDGUI: Implementation as GUI
Uses JOptionPane dialog windows
String[] commands = {"Add/Change Entry", "Look Up Entry, "Remove Entry", "Save Directory", "Exit};
do {
choice = JOptionPane.showOptionDialog(
null, // No parent
Select a Command, // Prompt message
PhoneDirectory, // window title
JOptionPane.YES_NO_CANCEL_OPTION, // Option type
JOptionPane.QUESTIONE_MESSAGE, // Message type
null, // Accompanying icon
command, // Choice names (array)
command[commands.length 1]); // Default command
switch (choice) {
case 0: doAddChangeEntry(); break;
case 1: doLookupEntry(); break;
case 2: doRemoveEntry(); break;
case 3:
case 4: doSave(): break;
default: // Do nothing.
}
} while (choice != commands.length 1);
21
PDConsoleUI: Implementation Using a
Console
Uses System.out to display the menu of choices and
results.
It also uses a Scanner object (scIn) created out of
System.in to read data from the keyboard.
// Constructor
/** Default constructor. */
public PDConsoleUI() {
scIn = new Scanner(System.in);
}
choice = scIn.nextInt(); // Get next choice.
scIn.nextLine(); // Skip trailing newline.
22
ArrayBasedPD that Implements
PhoneDirectory Interface, Private Data Fields
Data Field Attribute
private static final int INITIAL_CAPACITY The initial capacity of the array (or the array
size). It has the final attribute so change is
not allowed.
private int capacity The current capacity (or the array size), so
the capacity changes
private int size The number of entries held in the directory
23
The Private Methods of the
ArrayBasedPD Class
private int find(String name) Searches the array for the name and
returns the position of the name; -1
indicates that the name was not found
private void add(String name, String Adds to the array a new entry with the given
number) name and number
private void reallocate() Creates a new array with twice the capacity
of the current one with the same entries
24
DirectoryEntry Class
Constructor Action
public DirectoryEntry(String name, String Create an entry with the name and the
number) number
Method Action
public void setNumber(String number) Sets the number of an individual to the give
number
25
Implementing and Testing the Array-Based
Phone Directory
The main loop of ReadData has two notable points
The while and if statements combine an assignment with a
conditional statement
The break statement allows exiting of the while loop without
storing an entry
// Read each name and number and add the entry to the array.
BufferedReader in = new BufferedReader(new FileReader(new File (this.filename)))
while ((name = in.readLine()) != null) { // Read name and number from successive lines.
if ((number = in.readLine()) != null) { break; } // No number read, exit loop.
// Add an entry for this name and number.
this.add(name, number);
}
26
Code Reuse
27
Maximizing Code Reuse
28
Abstract Data Types
29