Software Design Overview 2 - PowerPoint PPT Presentation

1 / 50
About This Presentation
Title:

Software Design Overview 2

Description:

Date class: supports calendar class. day of week for 1st day, days in month, etc. ... display the calendar with a header // and a table of dates. int getMonth() const; ... – PowerPoint PPT presentation

Number of Views:36
Avg rating:3.0/5.0
Slides: 51
Provided by: alaneu
Category:

less

Transcript and Presenter's Notes

Title: Software Design Overview 2


1
Software Design Overview (2) Software Design
Stages (3 slides) Program Design -The
Traditional Approach (3) calendar Class (3
slides) date Class (2 slides) Implementing the
Calendar Class Error Handling -Program
Termination (2 slides) -Setting a Flag (3 slides)
Chapter 2 Object Design Techniques
C Exceptions (3 slides) Object Composition
timeCard Class (3 slides) Implementing
timeCard Class -Constructor -punchOut() Operator
Overloading -With Free Functions (3 slides) -With
Friend Functions (2 slides) -Stream I/O
Operators Operator Functions time24 Class (5
slides) Member Function Overloading -Implementati
on Summary Slides (15 slides)
2
Software Design Overview
  • A computer program begins with a problem that the
    client wants solved.
  • The process of building the program starts with
    an analysis of the problem.
  • It proceeds through a series of stages to produce
    a product that is reliable and easy to maintain.

3
Software Design Overview
  • Prior to the standardization of the software
    development life cycle
  • Programmers added code to software with little
    attention to its integration into the system.
  • Over time systems deteriorated and became so
    difficult to update that programmers had to
    develop new software to replace them.

4
Software Design Stages
  • Request
  • Client perceives a need for a software system to
    solve a problem.
  • A computer consultant undertakes a feasibility
    study for the project.
  • Analysis
  • A systems analyst develops the requirements of
    the system and creates a functional specification
    that includes a list of needs and special
    requirements.

5
Software Design Stages
  • Design
  • Translate the functional specification into an
    abstract model of the system.
  • Identify the components of the system and develop
    algorithms that will be used for implementation.
  • Implementation
  • Use a programming language and the design
    specification to code the different components of
    the system.

6
Software Design Stages
  • Testing
  • Check the program for logical and runtime errors
    and verify that the system meets the
    specifications of the client.
  • Maintenance
  • Periodically update the software to stay current
    and to respond to changing needs of the client.

7
Program DesignThe Traditional Approach
  • Uses a top-down strategy.
  • System viewed as a layered set of subprograms.
  • Execution begins in the main program and
    information flows in the system through a series
    of function calls and return values.
  • For large problems this approach can fail
  • Design changes in subprograms near the top of the
    hierarchy can require expensive, time-consuming
    changes in the subprograms at lower levels.

8
Program DesignObject Oriented Approach
  • More of a bottom-up approach
  • System viewed as interacting objects
  • Design focuses on identifying objects and their
    interactions through use of scenarios
  • Data (objects) are active rather than passive
  • UML (Unified Modeling Language)
  • Class diagrams
  • Use cases (users view of system)
  • Interaction Diagrams (sequences, collaborations,
    )

9
Program Testing Debugging
  • Unit testing
  • Integration testing
  • Verification meets requirements
  • Validation meets users needs
  • Syntax vs. Semantic (logical) errors
  • Black-box vs. White-box testing
  • Test data (inputs in range, out of range,
    boundary)

10
Program DesignMonthly Calendar Example
  • Request Display month/year calendar
  • Analysis Inputs? Form of display?
  • Design calendar class
  • public member functions
  • Required data support functions
  • Date class supports calendar class
  • day of week for 1st day,
  • days in month, etc.
  • Testing based on known calendars

11
(No Transcript)
12
(No Transcript)
13
(No Transcript)
14
date Class
15
date Class
16
Implementing the calendar Class
setMonth() // update the current month
void calendarsetMonth(int mm)
// verify that mm is a valid month if
(mm lt 1 mm gt 12) throw dateError("calendar
setMonth()",mm, "invalid month") //
set d to new month d.setMonth(mm)

17
Error handling Program Termination
Terminating the program in case of error time24
time24duration(const time24 t) // convert
times to minutes int currTime hour 60
minute int tTime t.hour 60 t.minute //
if t is earlier time, throw exception if (tTime
lt currTime) cerr ltlt "time24 duration()
argument " ltlt " is an earlier time" ltlt
endl exit(1) else return time24(0,
tTime-currTime)
18
Error HandlingSetting a Flag
Implementing duration() with an error
flag time24 time24duration(const time24 t,
bool success) int
currTime hour 60 minute int tTime
t.hour 60 t.minute time24 returnTime //
default time 000 success true // assume
no error if (tTime lt currTime) success
false // error else returnTime
time24(0,tTime-currTime) return returnTime //
return 000
19
Error HandlingSetting a Flag
The programmer can have the calling statement
check the result of duration() by placing the
call within a conditional expression. bool
success time24 currTime, nextTime,
interval ... interval currTime.duration(nextTi
me, success) if (success
false) // check success and deal with an
error lttake appropriate
actiongt
20
C Exceptions
21
C Exceptions
Implementing duration() by throwing an
exception time24 time24duration(const time24
t) int currTime hour 60 minute int
tTime t.hour 60 t.minute // throw error
if t is earlier time if (tTime lt currTime)
throw rangeError("time24 duration() \
argument is an earlier time") else return
time24(0, tTime-currTime)
22
C Exceptions
// call to function and handling of error try
time1.duration(time2) catch
(rangeError re) cerr ltlt re.what()
// now do something to handle error here
23
Object Composition
  • Object Composition
  • refers to a condition that exists when a class
    contains one or more data members that are
    objects of class type.
  • Class included by composition supplier
    class.
  • Class that includes an object by composition
    client class.

24
(No Transcript)
25
(No Transcript)
26
(No Transcript)
27
Implementing the timeCard Class Constructor
Constructor // use initialization list to
initialize // data members. timeCardtimeCard(
const string ssno, double rate, int
punchInHr, int punchInMin) workerID(ssno),
payrate(rate), hasPunched(false),
punchInTime(punchInHr, punchInMin)
28
Operator Overloading
For programmer-defined objects, functions are
often needed to enable the comparisons.
Example as a free named function // compare
two time24 objects bool equalTime(const time24
a, const time24 b)
// a and b are equal if they have the
// same hour and minute values Return
a.getHour() b.getHour()
a.getMinute() b.getMinute()
29
Operator Overloading- with Free Functions
  • Operators (, lt, , ) may be overloaded as
    free functions or as class member functions.
  • // compare two time24 objects
  • bool operator (const time24 a,
  • const time24 b)
  • Return (a.getHour() b.getHour())
  • (a.getMinute() b.getMinute())

30
Operator Overloading- With Friend Functions
  • Overloading an operator as a free function raises
    efficiency issues
  • The function is independent of the class
  • Its implementation must use member functions to
    access the appropriate data members.
  • If a class does not provide the appropriate
    access functions,
  • The operator cannot be overloaded as a free
    function.

31
Operator Overloading- With Friend Functions
  • C allows a free function to be declared as a
    friend function in the class
  • A friend function has access to the private
    members of the class.
  • Denoted in the class declaration by placing the
    keyword friend immediately before its prototype.
  • Despite having access to the private data
    members, a friend is not a member function of the
    class.

32
Operator Overloading- with Friend Functions
  • Friend function example.
  • // prototype
  • friend bool operator (const time24 a,
  • const
    time24 b)
  • // implementation (not a class member function)
  • bool operator (const time24 a,
  • const time24 b)
  • Return (a.hour b.hour) (a.minute
    b.minute)

33
Operator Overloading- Stream I/O Operators
A class can overload the stream operators ltlt and
gtgt as friend functions. operator function
prototype for each operation (Output)
ltlt friend ostream operatorltlt (ostream ostr,
const className obj) (Input) gtgt istream
operatorgtgt (istream istr, className obj)
34
Member Function Overloading
// update time by adding a time24 object // or
an int time24 operator (const time24 rhs) //
lhs rhs time24 operator (int min) //
lhs min
35
Member Function Overloading-Implementation-
// implement by using addition with //
operands this and rhs time24 time24operator
(const time24 rhs) // add this and rhs using
overloaded // operator this this
rhs // return a reference to the current //
object return this
36
Lecture 3 (start here)
  • Take a look at rational class example

37
Summary Slide 1
  • - The software life cycle consists of
  • A Request phase
  • An Analysis phase
  • A Design phase
  • An Implementation phase
  • A Testing phase
  • The Maintenance phase
  • - All share equal importance in the Software
    Development Lifecycle

38
Summary Slide 2
- The request phase - Meet with the client to
discuss the needs and requirements for a
software system. - Perform a feasibility study
to see if building a software system is cost
effective.
39
Summary Slide 3
- The analysis phase - Determine the system
requirements. - Systems analyst determines
requirements and is the intermediary between
the client and the software
engineers. - Result a functional specification
of the software system that includes a list of
needs and special requirements.
40
Summary Slide 4
- The design phase - Create abstract model of
the problem. - Identify objects building blocks
of the program. - Determine how
objects collaborate and interact to solve the
problem. - Create class declarations, including
their attributes and public member functions.
- Describe how classes are
related - Design the algorithms that allow the
classes to effectively interact.
41
Summary Slide 5
- The implementation phase - Convert the design
into a program. - Implement the classes
independently and verify the action of their
member functions. - Implement program units that
coordinate object interaction. - Code the main
program that manages the overall execution of the
software system. - Often, the implementation
stage will discover errors or oversights in
design.
42
Summary Slide 6
- The Testing Phase - Analysis, design, and
implementation phases interact to bring about
modifications and corrections to the
specifications and the code. - effective
interaction among the phases depends on
frequent and systematic testing. - Test the
classes and functions which are the individual
units of the software system - perform
integrative testing to ensure that the units fit
together to create a program that runs correctly
and efficiently.
43
Summary Slide 7
- Program maintenance phase - Begins as soon as
the client installs the system. - The client
will identify bugs or features that must be
changed or added. - A client may add new
hardware and/or find new applications for the
software. - Modern software systems must be
regularly upgraded or they will eventually
become obsolete and unusable.
44
Summary Slide 8
  • - Handling errors during function execution is
    an important aspect of program design.
  • - There are three fundamental ways to handle
    errors
  • Output an error message and terminate the
    program. - Generally avoided
    unless necessary.
  • Return a Boolean flag from the function call
    indicating that an error occurred. - Gra
    nts the advantage of leaving the decision about
    how to handle the error to the calling code
    block.
  • use the C exception mechanism. - The
    best approach.

45
Summary Slide 9
- C exceptions are handled by three
keywords - try - Function calls and code that
may generate an exception are placed in a try
block.
46
Summary Slide 9a
- catch - The exception handler. - Outputs an
error message and either takes corrective action
or terminates the program.
47
Summary Slide 9b
- throw - Bypasses the normal function return
mechanism searches chain of previous function
calls until it locates a catch block.
48
Summary Slide 10
- Operator overloading - important feature of
object design in C. - redefines an operator to
accept operands of the class type. - Designing
a class to take advantage of familiar operator
notation makes the class easier to use and
extends its flexibility.
49
Summary Slide 11
- 1st way to overload an operator - implement
a free function using the operator function
format. - requires the use of
class member functions that give the function
access to the private data of an object. - 2nd
way to overload an operator - declare an
operator function as a friend of a
class. - The function is not a class member
but has access to the private section of the
class. - This technique avoids calling class
access functions.
50
Summary Slide 12
- Some operators must be overloaded as class
member functions. - Overload unary operators
and binary operators that modify an object as
member functions. - An operator
overloaded in this fashion has one less
operand than the corresponding operator
function. - In the case of a binary operator,
the left operand is the object itself, and the
right operand is the argument. - A unary
operator has no argument list.
Write a Comment
User Comments (0)
About PowerShow.com