1 Abstract Data Types (ADT) 4 Why use the objects? The need for - - PDF document

1
SMART_READER_LITE
LIVE PREVIEW

1 Abstract Data Types (ADT) 4 Why use the objects? The need for - - PDF document

1 Last update: 16 April 2004 Programming in the large Bertrand Meyer Chair of Software Engineering Programming in the large - Lecture 3 Reading assignment for next week 2 OOSC2: Chapter 3: Modularity Chapter 6: Abstract Data Types


slide-1
SLIDE 1

1

Programming in the large - Lecture 3

1 Chair of Software Engineering

Programming in the large

Bertrand Meyer

Last update: 16 April 2004

Programming in the large - Lecture 3

2 Chair of Software Engineering

Reading assignment for next week

OOSC2: Chapter 3: Modularity Chapter 6: Abstract Data Types

Programming in the large - Lecture 3

3 Chair of Software Engineering

Lecture 3: Abstract Data Types

slide-2
SLIDE 2

2

Programming in the large - Lecture 3

4 Chair of Software Engineering

Abstract Data Types (ADT)

Why use the objects? The need for data abstraction Moving away from the physical representation Abstract data type specifications Applications to software design

Programming in the large - Lecture 3

5 Chair of Software Engineering

The first step

A system performs certain actions on certain data. Basic duality: Functions [or: Operations, Actions] Objects [or: Data]

Action Object Processor

Programming in the large - Lecture 3

6 Chair of Software Engineering

Finding the structure

The structure of the system may be deduced from an analysis of the functions (1) or the objects (2). Resulting analysis and design method: Process-based decomposition: classical (routines) Object-oriented decomposition

slide-3
SLIDE 3

3

Programming in the large - Lecture 3

7 Chair of Software Engineering

Arguments for using objects

Reusability: Need to reuse whole data structures, not just operations Extendibility, Continuity: Objects remain more stable over time.

Employee information Hours worked Produce Paychecks Paychecks

Programming in the large - Lecture 3

8 Chair of Software Engineering

Object technology: A first definition

Object-oriented software construction is the approach to system structuring that bases the architecture of software systems on the types of

  • bjects they manipulate — not on “the” function

they achieve.

Programming in the large - Lecture 3

9 Chair of Software Engineering

The O-O designer’s motto

Ask NOT first WHAT the system does: Ask WHAT it does it TO!

slide-4
SLIDE 4

4

Programming in the large - Lecture 3

10 Chair of Software Engineering

Issues of object-oriented design

How to find the object types. How to describe the object types. How to describe the relations and commonalities between object types. How to use object types to structure programs.

Programming in the large - Lecture 3

11 Chair of Software Engineering

Description of objects

Consider not a single object but a type of objects with similar properties. Define each type of objects not by the objects’ physical representation but by their behavior: the services (FEATURES) they offer to the rest of the world. External, not internal view: ABSTRACT DATA TYPES

Programming in the large - Lecture 3

12 Chair of Software Engineering

The theoretical basis

The main issue: How to describe program objects (data structures): Completely Unambiguously Without overspecifying?

(Remember information hiding)

slide-5
SLIDE 5

5

Programming in the large - Lecture 3

13 Chair of Software Engineering

A stack, concrete object

count representation (array_up) capacity

representation [count] := x “Push” x on stack representation: count := count + 1

1

x x

Programming in the large - Lecture 3

14 Chair of Software Engineering

A stack, concrete object

count representation (array_up) capacity

representation [count] := x

free (array_down) 1 representation

“Push” x on stack representation: count := count + 1 representation [free] := x “Push” x on stack representation: free := free - 1

1

x x x

Programming in the large - Lecture 3

15 Chair of Software Engineering

A stack, concrete object

count representation (array_up) capacity

representation [count] := x

free (array_down) 1 representation

n new (linked) item item previous item previous previous

“Push” x on stack representation: count := count + 1 representation [free] := x “Push” x on stack representation: free := free - 1 “Push” operation: new (n) n.item := x n.previous := last head := n

1

x

slide-6
SLIDE 6

6

Programming in the large - Lecture 3

16 Chair of Software Engineering

Stack: An Abstract Data Type (ADT)

Types: STACK [G]

  • - G: Formal generic parameter

Functions (Operations): put: STACK [G] × G → STACK [G] remove: STACK [G] → STACK [G] item: STACK [G] → G empty: STACK [G] → BOOLEAN new: STACK [G]

Programming in the large - Lecture 3

17 Chair of Software Engineering

Using functions to model operations

put

,

=

( )

s x s’

Programming in the large - Lecture 3

18 Chair of Software Engineering

Reminder: Partial functions

A partial function, identified here by →, is a function that may not be defined for all possible arguments. Example from elementary mathematics: inverse: ℜ → ℜ, such that inverse (x) = 1 / x

slide-7
SLIDE 7

7

Programming in the large - Lecture 3

19 Chair of Software Engineering

The STACK ADT (continued)

Preconditions: remove (s: STACK [G]) require not empty (s) item (s: STACK [G]) require not empty (s) Axioms: For all x: G, s: STACK [G] item (put (s, x)) = x remove (put (s, x)) = s empty (new)

(or: empty (new) = True)

not empty (put (s, x))

(or: empty (put (s, x)) = False)

put (

, ) =

s x s’

Programming in the large - Lecture 3

20 Chair of Software Engineering

Exercises

Adapt the preceding specification of stacks (LIFO, Last-In First-Out) to describe queues instead (FIFO). Adapt the preceding specification of stacks to account for bounded stacks, of maximum size capacity. Hint: put becomes a partial function.

Programming in the large - Lecture 3

21 Chair of Software Engineering

End of lecture 3