The Software Challenge

offbeatnothingSoftware and s/w Development

Dec 2, 2013 (3 years and 8 months ago)

94 views

1

The Software Challenge


People

may

come

and

go,

but

software

may

remain


A software product is often expected to be used for an
extended period of time by someone who did not
write the program and who is not intimately familiar
with its internal design


Software

may

evolve


New features may be added, environments may
change, so initial specification may be incomplete

2

The Software Specification Challenge


Software

specification

is

not

easy


It should be generated at the beginning of project and
maintained up
-
to
-
date while the software goes
through changes


It should be clarified through extensive interaction
between the users and the system analyst, and then
approved by the users


It should be clear and understandable to any
programmer


3

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

4

Software Life Cycle Models


Waterfall

model
:

simplest

way

of

organizing

activities

that

transform

software

from

one

stage

to

another


Activities

are

performed

in

sequence

and

the

results

of

one

flows

into

the

next




Waterfall Model

1
Requirements

(requirements

are

determined)

2
Analysis

(requirements

are

analyzed)

3
Design

(components

are

designed)

4
Implementation

(components

are

implemented)

5
Testing

(components

are

assembled

and

tested

as

a

whole)



5

6

Software Life Cycle Models


Waterfall

model

is

simple

but

unworkable


Fundamental flaw is assumption that each stage can
and must be completed before the next one occurs


Sometimes,

it

is

not

until

the

product

is

finished

that

the

user

can

fully

express

his

or

her

requirements




Software Life Cycle Activities

1)
Requirements

Specification

2)
Design

a.
Architectural Design

b.
Component Design

c.
Detailed Design

3)
Implementation


4)
Test

a.
Unit Test

b.
Integration Test

c.
Acceptance Test

5)
Installation

6)
Maintenance


7

8

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


9

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


10

Pre
-

and Postconditions


Precondition
:

a

statement

of

any

assumptions

or

constraints

on

the

method

data

before

the

method

begins

execution


Postcondition
:

a

statement

that

describes

the

result

of

executing

a

method

11

Using Abstraction to Manage Complexity


Abstraction

is

a

model

of

a

physical

entity

or

activity


Abstraction

helps

programmers

deal

with

complex

issues

in

a

piecemeal

fashion


Procedural abstraction
: distinguish what is to be
achieved by a procedure from its implementation


12

Using Abstraction to Manage Complexity
(cont’d)


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


An Example: Telephone Directory


Maintain

a

collection

of

telephone

directory

entries,

where

each

entry

is

referred

to

by

a

unique

name
.


Can

read

from

a

file,

save

to

a

file,

lookup,

add,

remove,

and

change

phone

number

13

Dependencies Among Possible Actions

14

Object Relations

15

Things you already know (about) ...


Java

programs

(you

know

and

love)


Classes

and

objects

(you

can

create

and

use)


Inheritance

(you

understand

and

can

extend)


Abstract

classes

(you

remember

what

they

are)


Interfaces

(your

contractual

obligations)



Interfaces

are

a

key

idea

in

CSC
220

16

17

Interfaces


The

interface

specifies

the

names,

parameters,

and

return

values

of

the

ADT

methods

without

specifying

how

the

methods

perform

their

operations

and

without

specifying

how

the

data

is

internally

represented


Each

class

that

implements

an

interface

must

provide

the

definitions

of

all

methods

declared

in

the

interface


18

Interfaces


You

cannot

instantiate

an

interface
;

that

is,

can’t

invoke

“new

INTERFACE_NAME”


You

can

declare

a

variable

that

has

an

interface

type

and

use

it

to

reference

an

actual

object


A

Java

interface

is

a

contract

between

the

interface

designer

and

the

programmer

who

codes

a

class

that

implements

the

interface

Public Methods of PhoneDirectory Interface

19

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,
String number)

Changes the number of the individual with the
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

20

The PDUserInterface Interface


There is only one required public method,
processCommands, which takes input from the user and
executes the command


Two different implementations:


PDGUI: a GUI
-
based implementation


PDConsoleUI: a console
-
based implementation


21

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);

22

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.

ArrayBasedPD that Implements

PhoneDirectory Interface, Private Data Fields

23

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

private DirectoryEntry[] theDirectory

The directory realized as an array of
DirectoryEntry objects

private String fileName

The name of the data file

private boolean modified

A boolean variable that maintains whether
any change has been made to any entry
since the last time the data were saved or
loaded. Data is automatically saved at
closing if this variable is
true
.

The Private Methods of the

ArrayBasedPD Class

24

Private Method

Action

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
number)

Adds to the array a new entry with the given
name and number

private void reallocate()

Creates a new array with twice the capacity
of the current one with the same entries

DirectoryEntry Class

25

Data Field

Attribute

private String name

The name of an individual

private String number

The phone number of the individual

Constructor

Action

public DirectoryEntry(String name, String
number)

Create an entry with the name and the
number

Method

Action

public String getName()

Retrieves the name of an individual

public String getNumber()

Retrieves the number of an individual

public void setNumber(String number)

Sets the number of an individual to the give
number

26

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);

}

Code Reuse


A

part

of

program

can

be

reused

for

other

programs



If

there

is

a

code

for

maintaining

a

phone

book

(adding,

removing,

editing,

loading,

and

storing),

some

of

the

ideas

and

concepts

used

for

the

code

can

be

used

for

writing

a

code

for

maintaining

business

cards
.


27

Maximizing Code Reuse


View

the

program

to

be

developed

as

a

process

of

dealing

with

data


The data has to be maintained during execution of the
program


The data may be read from and/or stored into files


The data may be generated from input


Various operations on the data may be performed


28

29

Abstract Data Types


Abstract

data

type

(ADT)

=

the

combination

of

data

together

with

its

methods

(how

the

data

objects

are

accessed)


ADTs

specify

a

set

of

required

methods,

but

do

not

specify

how

those

methods

should

be

implemented

(that’s

why

they

are

called

“abstract”)


“Data

structures”

quite

often

refer

to

ADTs



For

frequently

used

ADTs

the

most

efficient

universal

(applicable

to

the

vast

majority

of

programming

languages)

implementations

are

known