Top Banner
1 Main Index Conten ts 1 Main Index Conten ts Software Design Overvie w (2) Software Design Stages (3 slides) Program Design Program Design - The Traditional Appr oach (3) calendar Class (3 slides) date Class (2 slides) Implementing the Calend ar Class Chapter 2 Chapter 2 Object Design Techniques Object Design Techniques C++ Exceptions (3 slides) Object Composition timeCard Class (3 slides) Implementing timeCard Implementing timeCard Class 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 Overloa ding - -Implementation
59

Main Index Contents 11 Main Index Contents Software Design OverviewSoftware Design Overview Software Design Overview (2) Software Design Overview Software.

Dec 20, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Main Index Contents 11 Main Index Contents Software Design OverviewSoftware Design Overview Software Design Overview (2) Software Design Overview Software.

1 Main IndexMain Index ContentsContents1 Main IndexMain Index ContentsContents

Software Design Overview (2)

Software Design Stages (3 slides)

Program DesignProgram Design-The Traditional Approach (3)

calendar Class (3 slides)

date Class (2 slides)

Implementing the Calendar Class

Error HandlingError Handling-Program Termination (2 slides)-Setting a Flag (3 slides)

Chapter 2 Chapter 2 – – Object Design TechniquesObject Design Techniques

C++ Exceptions (3 slides)

Object Composition

timeCard Class (3 slides)

Implementing timeCard ClassImplementing 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--Implementation

Summary Slides (15 slides)

Page 2: Main Index Contents 11 Main Index Contents Software Design OverviewSoftware Design Overview Software Design Overview (2) Software Design Overview Software.

2 Main IndexMain Index ContentsContents

Software Design OverviewSoftware 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.

Page 3: Main Index Contents 11 Main Index Contents Software Design OverviewSoftware Design Overview Software Design Overview (2) Software Design Overview Software.

3 Main IndexMain Index ContentsContents

Software Design OverviewSoftware 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.

Page 4: Main Index Contents 11 Main Index Contents Software Design OverviewSoftware Design Overview Software Design Overview (2) Software Design Overview Software.

4 Main IndexMain Index ContentsContents4 Main IndexMain Index ContentsContents

Software Design Stages 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.

Page 5: Main Index Contents 11 Main Index Contents Software Design OverviewSoftware Design Overview Software Design Overview (2) Software Design Overview Software.

5 Main IndexMain Index ContentsContents5 Main IndexMain Index ContentsContents

Software Design Stages 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.

Page 6: Main Index Contents 11 Main Index Contents Software Design OverviewSoftware Design Overview Software Design Overview (2) Software Design Overview Software.

6 Main IndexMain Index ContentsContents6 Main IndexMain Index ContentsContents

Software Design Stages 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 of the software to stay

current and to respond to changing needs of the client.

Page 7: Main Index Contents 11 Main Index Contents Software Design OverviewSoftware Design Overview Software Design Overview (2) Software Design Overview Software.

7 Main IndexMain Index ContentsContents

Program DesignProgram DesignThe Traditional ApproachThe Traditional Approach

The design phase of the software development life cycle translates the functional specifications from the analysis phase into an abstract model.

The traditional design approach uses a top-down strategy. – The model views a system 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.

Page 8: Main Index Contents 11 Main Index Contents Software Design OverviewSoftware Design Overview Software Design Overview (2) Software Design Overview Software.

8 Main IndexMain Index ContentsContents

Program DesignProgram DesignThe Traditional ApproachThe Traditional Approach

When the problem becomes too large this approach can fail: – The complexity overwhelms the ability of a

single person to manage the hierarchy of subprograms.

– Design changes in subprograms near the top of the hierarchy can require expensive, time-consuming changes in the subprograms at lower levels in the chart.

Page 9: Main Index Contents 11 Main Index Contents Software Design OverviewSoftware Design Overview Software Design Overview (2) Software Design Overview Software.

9 Main IndexMain Index ContentsContents9 Main IndexMain Index ContentsContents

Program DesignProgram DesignThe Traditional ApproachThe Traditional Approach

Su bP ro gram 2,1

Su bP ro gram 2

M ain P ro gram

Su bP ro gram 1,2Su bP ro gram 1,1

Su bP ro gram 1

Su bP ro gram 3,1

S u b p ro gra m 3

Page 10: Main Index Contents 11 Main Index Contents Software Design OverviewSoftware Design Overview Software Design Overview (2) Software Design Overview Software.

10 Main IndexMain Index ContentsContents10 Main IndexMain Index ContentsContents

CLASS calendar Declaration “d_cal.h”

class calendar{public:calendar(int m = 1, int y = 1900);// initialize the month and year for // display.

// precondition: month is in the // range 1 to 12 and year

// is 1900 or later

Page 11: Main Index Contents 11 Main Index Contents Software Design OverviewSoftware Design Overview Software Design Overview (2) Software Design Overview Software.

11 Main IndexMain Index ContentsContents11 Main IndexMain Index ContentsContents

CLASS calendar Declaration “d_cal.h”

void displayCalendar() const;// display the calendar with a header

// and a table of dates

int getMonth() const;// return the current month for the

// calendar

int getYear() const;// return the current year for the

// calendar

Page 12: Main Index Contents 11 Main Index Contents Software Design OverviewSoftware Design Overview Software Design Overview (2) Software Design Overview Software.

12 Main IndexMain Index ContentsContents12 Main IndexMain Index ContentsContents

CLASS calendar Declaration “d_cal.h”

void setMonth(int m);// update the month for the calendar// precondition: m must be in the

// range 1 to 12

void setYear(int y);// update the year for the calendar// precondition: y must be >= 1900

private:. . .

;

Page 13: Main Index Contents 11 Main Index Contents Software Design OverviewSoftware Design Overview Software Design Overview (2) Software Design Overview Software.

13 Main IndexMain Index ContentsContents

date Classdate Class

CLASS date Constructor “d_date.h”

date(int mm = 1, int dd = 1, int yy = 1900);Initializes the date with default January 1, 1900

CLASS date Operations “d_date.h”

int daysInMonth();Returns the number of days for the month. If

the year is a leap year, month 1 (February) returns 29int getMonth();

Returns the month for the current date

Page 14: Main Index Contents 11 Main Index Contents Software Design OverviewSoftware Design Overview Software Design Overview (2) Software Design Overview Software.

14 Main IndexMain Index ContentsContents

date Classdate Class

CLASS date Operations “d_date.h”

int getYear();Returns the year for the current date

bool isLeapYear();Return true if the year is a leap year, otherwise returns false

int numberOfDays();Return the number of days into the year

void setMonth(int mm);Update the month in the current date

void setYear(int yy);Update the year in the current date

Page 15: Main Index Contents 11 Main Index Contents Software Design OverviewSoftware Design Overview Software Design Overview (2) Software Design Overview Software.

15 Main IndexMain Index ContentsContents15 Main IndexMain Index ContentsContents

Implementing the calendar Implementing the calendar ClassClass

setMonth() :

// update the current month void calendar::setMonth(int mm)

{// verify that mm is a valid month

if (mm < 1 || mm > 12)

throw dateError("calendar setMonth():",mm, "invalid month");

// set d to new month

d.setMonth(mm); }

Page 16: Main Index Contents 11 Main Index Contents Software Design OverviewSoftware Design Overview Software Design Overview (2) Software Design Overview Software.

16 Main IndexMain Index ContentsContents

Error handling: Error handling: Program TerminationProgram Termination

Implementing duration() by terminating the program in case of error:time24 time24::duration(const time24& t) {// convert current time and time t to

// minutes

int currTime = hour * 60 + minute; int tTime = t.hour * 60 + t.minute;

// if t is earlier than the current time, // throw an exception

Page 17: Main Index Contents 11 Main Index Contents Software Design OverviewSoftware Design Overview Software Design Overview (2) Software Design Overview Software.

17 Main IndexMain Index ContentsContents

Error handling: Error handling: Program TerminationProgram Termination

if (tTime < currTime){

cerr << "time24 duration(): argument is an earlier time" << endl;

exit(1);}

else

return time24(0, tTime-currTime); }

Page 18: Main Index Contents 11 Main Index Contents Software Design OverviewSoftware Design Overview Software Design Overview (2) Software Design Overview Software.

18 Main IndexMain Index ContentsContents

Error Handling:Error Handling:Setting a FlagSetting a Flag

Implementing duration() with an error flag:

time24 time24::duration(const time24& t , bool& success)

{// convert current time and time t to

// minutes

int currTime = hour * 60 + minute;

int tTime = t.hour * 60 + t.minute;// time returned. default value of 0:00

// is the return

// time if an error occurs

time24 returnTime;

Page 19: Main Index Contents 11 Main Index Contents Software Design OverviewSoftware Design Overview Software Design Overview (2) Software Design Overview Software.

19 Main IndexMain Index ContentsContents

Error Handling:Error Handling:Setting a FlagSetting a Flag

// assume that no error will occursuccess = true;// if t is earlier than the current time, // assign false to success

if (tTime < currTime)success = false;

else// successful. assign duration to // returnTime

returnTime = time24(0, tTime-currTime);

return returnTime; }

Page 20: Main Index Contents 11 Main Index Contents Software Design OverviewSoftware Design Overview Software Design Overview (2) Software Design Overview Software.

20 Main IndexMain Index ContentsContents

Error Handling:Error Handling:Setting a FlagSetting 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(nextTime,

success);

if (success == false) // check success and deal with an error {

<take appropriate action> }

Page 21: Main Index Contents 11 Main Index Contents Software Design OverviewSoftware Design Overview Software Design Overview (2) Software Design Overview Software.

21 Main IndexMain Index ContentsContents21 Main IndexMain Index ContentsContents

C++ ExceptionsC++ Exceptions

o b jA

o b jB

m ain(){ . . .

o b jA .f(); < exc ep tio n hand ler>}

...o b jB .g() [in f()]

. . .

. . .< erro r> [in g()]

.. .

Exc ep tio n rep o rted b ac k to m ain()

Page 22: Main Index Contents 11 Main Index Contents Software Design OverviewSoftware Design Overview Software Design Overview (2) Software Design Overview Software.

22 Main IndexMain Index ContentsContents22 Main IndexMain Index ContentsContents

C++ ExceptionsC++ Exceptions

Implementing duration() by throwing an exception:

time24 time24::duration(const time24& t) {// convert current time and time t to

// minutes

int currTime = hour * 60 + minute;int tTime = t.hour * 60 + t.minute;

Page 23: Main Index Contents 11 Main Index Contents Software Design OverviewSoftware Design Overview Software Design Overview (2) Software Design Overview Software.

23 Main IndexMain Index ContentsContents23 Main IndexMain Index ContentsContents

C++ ExceptionsC++ Exceptions// if t is earlier than the current time, // throw an exception

if (tTime < currTime)

throw rangeError("time24 duration(): argument is an earlier time");

elsereturn time24(0, tTime-currTime);

}

Page 24: Main Index Contents 11 Main Index Contents Software Design OverviewSoftware Design Overview Software Design Overview (2) Software Design Overview Software.

24 Main IndexMain Index ContentsContents

Object CompositionObject CompositionObject 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.

Page 25: Main Index Contents 11 Main Index Contents Software Design OverviewSoftware Design Overview Software Design Overview (2) Software Design Overview Software.

25 Main IndexMain Index ContentsContents25 Main IndexMain Index ContentsContents

CLASS timeCard Declaration “d_tcard.h”

class timeCard {

public:timeCard(const string& ssno,

double rate, int punchInHour, int punchInMinute); 

void punchOut(const time24& t);// assign t to punchOutTime and set // hasPunched to true,

Page 26: Main Index Contents 11 Main Index Contents Software Design OverviewSoftware Design Overview Software Design Overview (2) Software Design Overview Software.

26 Main IndexMain Index ContentsContents26 Main IndexMain Index ContentsContents

CLASS timeCard Declaration “d_tcard.h”

void writeSalaryInfo();/* output a log that includes the

beginning and ending times for the day's work, the amount of time

worked, the pay rate and the earnings.

precondition: throw a rangeError exception if worker has not punched out (hasPunched == false)

*/

Page 27: Main Index Contents 11 Main Index Contents Software Design OverviewSoftware Design Overview Software Design Overview (2) Software Design Overview Software.

27 Main IndexMain Index ContentsContents27 Main IndexMain Index ContentsContents

CLASS timeCard Declaration “d_tcard.h”

private:string workerID;time24 punchInTime, punchOutTime;// supplier-class objects

double payrate;bool hasPunched;

};

Page 28: Main Index Contents 11 Main Index Contents Software Design OverviewSoftware Design Overview Software Design Overview (2) Software Design Overview Software.

28 Main IndexMain Index ContentsContents

Implementing the timeCard Implementing the timeCard Class: ConstructorClass: Constructor

Constructor:// use initialization list to initialize // data members.

timeCard::timeCard(const string& ssno, double rate, int punchInHour, int

punchInMinute):

workerID(ssno), payrate(rate), hasPunched(false),

punchInTime(punchInHour, punchInMinute)

{)

Page 29: Main Index Contents 11 Main Index Contents Software Design OverviewSoftware Design Overview Software Design Overview (2) Software Design Overview Software.

29 Main IndexMain Index ContentsContents

Implementing the timeCard Implementing the timeCard Class: punchOut()Class: punchOut()

punchOut():void timeCard::punchOut(const time24& t)

{

punchOutTime = t;

hasPunched = true;

}

Page 30: Main Index Contents 11 Main Index Contents Software Design OverviewSoftware Design Overview Software Design Overview (2) Software Design Overview Software.

30 Main IndexMain Index ContentsContents30 Main IndexMain Index ContentsContents

Operator OverloadingOperator Overloading

For programmer-defined objects, functions are needed to enable the comparisons.

Example:// 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();

}

Page 31: Main Index Contents 11 Main Index Contents Software Design OverviewSoftware Design Overview Software Design Overview (2) Software Design Overview Software.

31 Main IndexMain Index ContentsContents31 Main IndexMain Index ContentsContents

Operator OverloadingOperator Overloading- with Free Functions- with Free Functions

Operators may be overloaded as free functions or as class member functions.– The concepts have important

differences; their syntax is dealt with separately.

Page 32: Main Index Contents 11 Main Index Contents Software Design OverviewSoftware Design Overview Software Design Overview (2) Software Design Overview Software.

32 Main IndexMain Index ContentsContents32 Main IndexMain Index ContentsContents

Operator OverloadingOperator Overloading- with Free Functions- with Free Functions

A free function could be used to compare two class objects.

// compare two class objects

bool equalItem(const className& a, const className& b)

{

return a.getObject1()== b.getObject1() && a.getObject2() == b.getObject2();

}

Page 33: Main Index Contents 11 Main Index Contents Software Design OverviewSoftware Design Overview Software Design Overview (2) Software Design Overview Software.

33 Main IndexMain Index ContentsContents33 Main IndexMain Index ContentsContents

Operator OverloadingOperator Overloading- with Free Functions- with Free Functions

The same comparison can be made using operator overloading.

bool operator== (const className& lhs, const className& rhs);

Page 34: Main Index Contents 11 Main Index Contents Software Design OverviewSoftware Design Overview Software Design Overview (2) Software Design Overview Software.

34 Main IndexMain Index ContentsContents34 Main IndexMain Index ContentsContents

Operator OverloadingOperator Overloading- With Friend Functions- 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.

Page 35: Main Index Contents 11 Main Index Contents Software Design OverviewSoftware Design Overview Software Design Overview (2) Software Design Overview Software.

35 Main IndexMain Index ContentsContents35 Main IndexMain Index ContentsContents

Operator OverloadingOperator Overloading- With Friend Functions- 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.

Page 36: Main Index Contents 11 Main Index Contents Software Design OverviewSoftware Design Overview Software Design Overview (2) Software Design Overview Software.

36 Main IndexMain Index ContentsContents36 Main IndexMain Index ContentsContents

Operator OverloadingOperator Overloading- Stream I/O Operators- Stream I/O Operators

A class can overload the stream operators << and >> as friend functions.

operator function prototype for each operation:

(Output) <<:friend ostream& operator<< (ostream& ostr, const className& obj);

(Input) >>:

istream& operator>> (istream& istr, className& obj);

Page 37: Main Index Contents 11 Main Index Contents Software Design OverviewSoftware Design Overview Software Design Overview (2) Software Design Overview Software.

37 Main IndexMain Index ContentsContents

Assume the string s = "Hello" and t = " World!". – The string expression s + t returns a string that is

the concatenation of s and t. The op. function for the op. + with arguments

lhs and rhs and return type string is

Operator FunctionsOperator Functions

string operator+ (const string& lhs, const string&

rhs);u = s + t

s tr ing o pe rato r+ ( c o ns t s tr ing& lhs , c o ns t s tr ing& rhs )

func tio n c al l

r e turn value"H e llo W o r ld!"

Page 38: Main Index Contents 11 Main Index Contents Software Design OverviewSoftware Design Overview Software Design Overview (2) Software Design Overview Software.

38 Main IndexMain Index ContentsContents38 Main IndexMain Index ContentsContents

CLASS time24 Declaration “d_time24.h”

class time24{

public:// constructor with starting time

time24(int h = 0, int m = 0);

// binary + operators: add minute// and time24 objects

friend time24 operator+ (const time24& lhs, const time24&

rhs);friend time24 operator+

(const time24& lhs, int min);friend time24 operator+

(int min, const time24& rhs);

Page 39: Main Index Contents 11 Main Index Contents Software Design OverviewSoftware Design Overview Software Design Overview (2) Software Design Overview Software.

39 Main IndexMain Index ContentsContents39 Main IndexMain Index ContentsContents

CLASS time24 Declaration “d_time24.h”

// binary - operator: subtracts two time24 // objects if rhs is not earlier than lhs. // if this precondition is not satisfied, // throw rangeError exception

friend time24 operator- (const time24& lhs, const time24&

rhs);

// comparison operators

friend bool operator== (const time24& lhs, const time24&

rhs);friend bool operator<

(const time24& lhs, const time24& rhs);

. . .

Page 40: Main Index Contents 11 Main Index Contents Software Design OverviewSoftware Design Overview Software Design Overview (2) Software Design Overview Software.

40 Main IndexMain Index ContentsContents40 Main IndexMain Index ContentsContents

CLASS time24 Declaration “d_time24.h”

. . .private:

int hour, minute; // data members

void normalizeTime(); // put time units in range

};

Page 41: Main Index Contents 11 Main Index Contents Software Design OverviewSoftware Design Overview Software Design Overview (2) Software Design Overview Software.

41 Main IndexMain Index ContentsContents41 Main IndexMain Index ContentsContents

CLASS time24 Declaration - I/O operators “d_time24.h”

class time24 {public: . . .

// input a time for object tfriend istream& operator>>

(istream& istr, time24& t); 

// output the time in t as // hour:minute

friend ostream& operator<< (ostream& ostr, const time24&

t);

Page 42: Main Index Contents 11 Main Index Contents Software Design OverviewSoftware Design Overview Software Design Overview (2) Software Design Overview Software.

42 Main IndexMain Index ContentsContents42 Main IndexMain Index ContentsContents

CLASS time24 Declaration - I/O operators “d_time24.h”

private:int hour, minute;

// data membersvoid normalizeTime();

// put time units in range};

Page 43: Main Index Contents 11 Main Index Contents Software Design OverviewSoftware Design Overview Software Design Overview (2) Software Design Overview Software.

43 Main IndexMain Index ContentsContents

Member Function OverloadingMember 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

Page 44: Main Index Contents 11 Main Index Contents Software Design OverviewSoftware Design Overview Software Design Overview (2) Software Design Overview Software.

44 Main IndexMain Index ContentsContents

Member Function OverloadingMember Function Overloading-Implementation--Implementation-

// implement += by using addition with // operands *this and rhs

time24& time24::operator+= (const time24& rhs)

{// add *this and rhs using overloaded +

// operator

*this = *this + rhs;// return a reference to the current

// object

return *this;

}

Page 45: Main Index Contents 11 Main Index Contents Software Design OverviewSoftware Design Overview Software Design Overview (2) Software Design Overview Software.

45 Main IndexMain Index ContentsContents45 Main IndexMain Index ContentsContents

Summary Slide 1Summary Slide 1

§- The software life cycle consists of:

1) A Request phase

2) An Analysis phase

3) A Design phase

4) An Implementation phase

5) A Testing phase

6) The Maintenance phase

§- All share equal importance in the Software Development Lifecycle

Page 46: Main Index Contents 11 Main Index Contents Software Design OverviewSoftware Design Overview Software Design Overview (2) Software Design Overview Software.

46 Main IndexMain Index ContentsContents46 Main IndexMain Index ContentsContents

Summary Slide 2Summary 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.

Page 47: Main Index Contents 11 Main Index Contents Software Design OverviewSoftware Design Overview Software Design Overview (2) Software Design Overview Software.

47 Main IndexMain Index ContentsContents47 Main IndexMain Index ContentsContents

Summary Slide 3Summary 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.

Page 48: Main Index Contents 11 Main Index Contents Software Design OverviewSoftware Design Overview Software Design Overview (2) Software Design Overview Software.

48 Main IndexMain Index ContentsContents48 Main IndexMain Index ContentsContents

Summary Slide 4Summary Slide 4

§- The design phase (continued) - Translate data from the analysis phase into an

abstract model of the problem.- Identify the objects which are the building blocks of the program.

§- Determine how these objects should collaborate and interact to solve the problem.

Page 49: Main Index Contents 11 Main Index Contents Software Design OverviewSoftware Design Overview Software Design Overview (2) Software Design Overview Software.

49 Main IndexMain Index ContentsContents49 Main IndexMain Index ContentsContents

Summary Slide 4aSummary Slide 4a

§- The design phase cont - Create the declaration of the classes including their attributes and public member functions. §-Describe how the classes are related to each other

- Design the algorithms that allow the classes to effectively interact.

Page 50: Main Index Contents 11 Main Index Contents Software Design OverviewSoftware Design Overview Software Design Overview (2) Software Design Overview Software.

50 Main IndexMain Index ContentsContents50 Main IndexMain Index ContentsContents

Summary Slide 5Summary 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.

Page 51: Main Index Contents 11 Main Index Contents Software Design OverviewSoftware Design Overview Software Design Overview (2) Software Design Overview Software.

51 Main IndexMain Index ContentsContents51 Main IndexMain Index ContentsContents

Summary Slide 6Summary 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.

Page 52: Main Index Contents 11 Main Index Contents Software Design OverviewSoftware Design Overview Software Design Overview (2) Software Design Overview Software.

52 Main IndexMain Index ContentsContents52 Main IndexMain Index ContentsContents

Summary Slide 7Summary 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.

Page 53: Main Index Contents 11 Main Index Contents Software Design OverviewSoftware Design Overview Software Design Overview (2) Software Design Overview Software.

53 Main IndexMain Index ContentsContents53 Main IndexMain Index ContentsContents

Summary Slide 8Summary Slide 8

§- Handling errors during function execution is an important aspect of program design.

- There are three fundamental ways to handle errors: 1) Output an error message and terminate the

program.§- Generally avoided unless necessary.

2) Return a Boolean flag from the function call indicating that an error occurred.

§- Grants the advantage of leaving the decision about how to handle the error to the calling code block.

3) use the C++ exception mechanism.§- The best approach.

Page 54: Main Index Contents 11 Main Index Contents Software Design OverviewSoftware Design Overview Software Design Overview (2) Software Design Overview Software.

54 Main IndexMain Index ContentsContents54 Main IndexMain Index ContentsContents

Summary Slide 9Summary 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.

Page 55: Main Index Contents 11 Main Index Contents Software Design OverviewSoftware Design Overview Software Design Overview (2) Software Design Overview Software.

55 Main IndexMain Index ContentsContents55 Main IndexMain Index ContentsContents

Summary Slide 9aSummary Slide 9a

§- catch

- The exception handler.

- Outputs an error message and either takes corrective action or terminates the program.

Page 56: Main Index Contents 11 Main Index Contents Software Design OverviewSoftware Design Overview Software Design Overview (2) Software Design Overview Software.

56 Main IndexMain Index ContentsContents56 Main IndexMain Index ContentsContents

Summary Slide 9bSummary Slide 9b

§- throw

- Bypasses the normal function return mechanism searches chain of previous function calls until it

locates a catch block.

Page 57: Main Index Contents 11 Main Index Contents Software Design OverviewSoftware Design Overview Software Design Overview (2) Software Design Overview Software.

57 Main IndexMain Index ContentsContents57 Main IndexMain Index ContentsContents

Summary Slide 10Summary 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.

Page 58: Main Index Contents 11 Main Index Contents Software Design OverviewSoftware Design Overview Software Design Overview (2) Software Design Overview Software.

58 Main IndexMain Index ContentsContents58 Main IndexMain Index ContentsContents

Summary Slide 11Summary 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.

Page 59: Main Index Contents 11 Main Index Contents Software Design OverviewSoftware Design Overview Software Design Overview (2) Software Design Overview Software.

59 Main IndexMain Index ContentsContents59 Main IndexMain Index ContentsContents

Summary Slide 12Summary 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.