object-oriented design

19
C++ Programming: Program Design Including Data Structures, S econd Edition expanded by J. Goetz, 2004 Object-Oriented Design A technique for developing a program in which the solution is expressed in terms of objects -- self- contained entities composed of data and operations on that data. istream cin; // Input stream variables: type istream ostream cout; // Output stream variables: type ostream Private data << setf . . . Private data >> get . . . ignore cin cout setw 1

Upload: arvid

Post on 04-Jan-2016

41 views

Category:

Documents


0 download

DESCRIPTION

Object-Oriented Design. A technique for developing a program in which the solution is expressed in terms of objects -- self- contained entities composed of data and operations on that data. istream cin; // Input stream variables : type istream - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Object-Oriented Design

C++ Programming: Program Design Including Data Structures, Second Edition expanded by J. Goetz, 2004

Object-Oriented DesignA technique for developing a program in which

the solution is expressed in terms of objects -- self- contained entities composed of data and operations on that data.istream cin; // Input stream variables: type istream ostream cout; // Output stream variables: type ostream

Private data

<<

setf...

Private data

>>

get...

ignore

cin cout

setw

1

Page 2: Object-Oriented Design

C++ Programming: Program Design Including Data Structures, Second Edition expanded by J. Goetz, 2004

2

Two Programming Methodologies

Functional Object-Oriented Decomposition Design

FUNCTION

FUNCTION

FUNCTION

OBJECT

Operations

Data

OBJECT

Operations

Data

OBJECT

Operations

Data

Page 3: Object-Oriented Design

C++ Programming: Program Design Including Data Structures, Second Edition expanded by J. Goetz, 2004

3

What is an object?

OBJECT

Operations

Data

set of functions

internal state

Page 4: Object-Oriented Design

C++ Programming: Program Design Including Data Structures, Second Edition expanded by J. Goetz, 2004

4

An object contains data and operations

Private data:

accoutNumber

balance

OpenAccount

WriteCheck

MakeDeposit

IsOverdrawn

GetBalance

checkingAccount

Page 5: Object-Oriented Design

C++ Programming: Program Design Including Data Structures, Second Edition expanded by J. Goetz, 2004

5

Three C++ Program Stages

other code from libraries,

etc.

other code from libraries,

etc.

written in machine language

written in machine language

written in machine language

written in machine language

written in C++

written in C++

via compiler via linker

SOURCE OBJECT EXECUTABLE

myprog.cpp myprog.obj myprog.exe

Page 6: Object-Oriented Design

C++ Programming: Program Design Including Data Structures, Second Edition expanded by J. Goetz, 2004

6

SEQUENCE

Statement Statement Statement . . .

Page 7: Object-Oriented Design

C++ Programming: Program Design Including Data Structures, Second Edition expanded by J. Goetz, 2004

7

SELECTION (branch)

IF Condition THEN Statement1 ELSE Statement2

Statement1 Statement

Statement2

Condition . . .

True

False

Page 8: Object-Oriented Design

C++ Programming: Program Design Including Data Structures, Second Edition expanded by J. Goetz, 2004

8

LOOP (repetition)

Statement

Condition. . .

False

True

WHILE Condition DO Statement1

Page 9: Object-Oriented Design

C++ Programming: Program Design Including Data Structures, Second Edition expanded by J. Goetz, 2004

9

SUBPROGRAM (function)

SUBPROGRAM1 . . .

SUBPROGRAM1 a meaningful collection of SEQUENCE, SELECTION, LOOP, SUBPROGRAM

Page 10: Object-Oriented Design

C++ Programming: Program Design Including Data Structures, Second Edition expanded by J. Goetz, 2004

10

Computer Components

Arithmetic Logic Unit

Control Unit

Auxiliary StorageDevice

Memory Unit ( RAM & Registers )

Central Processing Unit ( CPU )

Input Device

Output Device

Peripherals

Page 11: Object-Oriented Design

C++ Programming: Program Design Including Data Structures, Second Edition expanded by J. Goetz, 2004

11

Program With Several Functions

main function

square function

cube function

Page 12: Object-Oriented Design

C++ Programming: Program Design Including Data Structures, Second Edition expanded by J. Goetz, 2004

12

Output StatementsSYNTAX

It converts (appends) the right-hand operand to a sequence of characters (to an output stream – an endless sequence of characters) which goes to the standard output device.

These examples yield the same output:

cout << “The answer is “ ;

cout << 3 * 4 ;

cout << “The answer is “ << 3 * 4 ;

cout << Expression << Expression . . . ;

Page 13: Object-Oriented Design

C++ Programming: Program Design Including Data Structures, Second Edition expanded by J. Goetz, 2004

13

Output StatementsSYNTAX

It converts (appends) the right-hand operand to a sequence of characters (to an output stream – an endless sequence of characters) which goes to the standard output device.

These examples yield the same output:

cout << “The answer is “ ;

cout << 3 * 4 ;

cout << “The answer is “ << 3 * 4 ;

cout << Expression << Expression . . . ;

Page 14: Object-Oriented Design

C++ Programming: Program Design Including Data Structures, Second Edition expanded by J. Goetz, 2004

No I/O is built into C++

• instead, a library provides input stream and output stream

Keyboard Screenexecutingprogram

istream ostream

14

Page 15: Object-Oriented Design

C++ Programming: Program Design Including Data Structures, Second Edition expanded by J. Goetz, 2004

SYNTAX

These examples yield the same result.

cin >> length ;

cin >> width ;

cin >> length >> width ;

Input Statements

cin >> Variable >> Variable . . . ;

15

Page 16: Object-Oriented Design

C++ Programming: Program Design Including Data Structures, Second Edition expanded by J. Goetz, 2004

No I/O is built into C++

• Instead, a library provides an output stream

Screenexecutingprogram

ostream

16

Page 17: Object-Oriented Design

C++ Programming: Program Design Including Data Structures, Second Edition expanded by J. Goetz, 2004

17

C++ Data TypesC++ Data Types

structured

array struct union class

address

pointer reference

simple

integral enum

char short int long bool

floating

float double long double

Page 18: Object-Oriented Design

C++ Programming: Program Design Including Data Structures, Second Edition expanded by J. Goetz, 2004

18

C++ Simple Data TypesC++ Simple Data Types

simple types

integral floating

char short int long bool enum float double long double

unsigned

Page 19: Object-Oriented Design

C++ Programming: Program Design Including Data Structures, Second Edition expanded by J. Goetz, 2004

Integration Testing Approaches

Ensures correct overall design logic and the interfaces between modulesare correct.

Ensures individual moduleswork together correctly, beginning with the lowest level.

TOP-DOWN

Assumption: the lower levels

work correctly

BOTTOM-UP

USES: placeholder USES: a test driver to callmodule “stubs” to test the functions being tested.the order of calls. A stub may consist a single/ Effective in a group programming group trace/debug output statements environment where each programmer has

tested already own modules/functions.