1
play

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


  1. 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 Chair of Software Engineering Programming in the large - Lecture 3 3 Lecture 3: Abstract Data Types Chair of Software Engineering Programming in the large - Lecture 3 1

  2. Abstract Data Types (ADT) 4 � Why use the objects? � The need for data abstraction � Moving away from the physical representation � Abstract data type specifications � Applications to software design Chair of Software Engineering Programming in the large - Lecture 3 The first step 5 � A system performs certain actions on certain data. � Basic duality: � Functions [or: Operations, Actions] � Objects [or: Data] Action Object Processor Chair of Software Engineering Programming in the large - Lecture 3 Finding the structure 6 � 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 Chair of Software Engineering Programming in the large - Lecture 3 2

  3. Arguments for using objects 7 � Reusability: Need to reuse whole data structures, not just operations � Extendibility, Continuity: Objects remain more stable over time. Employee information Produce Paychecks Paychecks Hours worked Chair of Software Engineering Programming in the large - Lecture 3 Object technology: A first definition 8 � Object-oriented software construction is the approach to system structuring that bases the architecture of software systems on the types of objects they manipulate — not on “the” function they achieve. Chair of Software Engineering Programming in the large - Lecture 3 The O-O designer’s motto 9 � Ask NOT first WHAT the system does: Ask WHAT it does it TO! Chair of Software Engineering Programming in the large - Lecture 3 3

  4. Issues of object-oriented design 10 � 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. Chair of Software Engineering Programming in the large - Lecture 3 Description of objects 11 � 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 Chair of Software Engineering Programming in the large - Lecture 3 The theoretical basis 12 � The main issue: How to describe program objects (data structures): � Completely � Unambiguously � Without overspecifying? (Remember information hiding) Chair of Software Engineering Programming in the large - Lecture 3 4

  5. A stack, concrete object 13 capacity x “Push” x on stack representation : x representation [ count ] := x count (array_up) count := count + 1 1 representation Chair of Software Engineering Programming in the large - Lecture 3 A stack, concrete object 14 capacity “Push” x on stack representation : count x representation [ count ] := x (array_up) count := count + 1 1 representation x “Push” x on stack representation : representation [ free ] := x (array_down) free := free - 1 free x 1 representation Chair of Software Engineering Programming in the large - Lecture 3 A stack, concrete object 15 capacity “Push” x on stack representation : representation [ count ] := x count (array_up) count := count + 1 1 representation “Push” x on stack representation : representation [ free ] := x (array_down) free := free - 1 x free 1 representation “Push” operation: new new ( n ) item previous n n . item := x item previous n . previous := last (linked) previous head := n item Chair of Software Engineering Programming in the large - Lecture 3 5

  6. Stack: An Abstract Data Type (ADT) 16 � 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 ] Chair of Software Engineering Programming in the large - Lecture 3 Using functions to model operations 17 ( ) , put = s x s’ Chair of Software Engineering Programming in the large - Lecture 3 Reminder: Partial functions 18 � 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 Chair of Software Engineering Programming in the large - Lecture 3 6

  7. The STACK ADT (continued) 19 � 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 put ( , ) = empty ( new ) (or: empty ( new ) = True ) s x s’ not empty ( put ( s , x )) (or: empty ( put ( s , x )) = False ) Chair of Software Engineering Programming in the large - Lecture 3 Exercises 20 � 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. Chair of Software Engineering Programming in the large - Lecture 3 21 End of lecture 3 Chair of Software Engineering Programming in the large - Lecture 3 7

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend