Chair of Software Engineering OOSC - Lecture 4 1 Object-Oriented Software Construction Bertrand Meyer.

Slides:



Advertisements
Similar presentations
Building Bug-Free O-O Software: An Introduction to Design By Contract A presentation about Design By Contract and the Eiffel software development tool.
Advertisements

SCOOP: Simple Concurrent Object-Oriented Programming Extend the pure, strongly typed, object-oriented language Eiffel with a general and powerful concurrency.
© Bertrand Meyer and Yishai Feldman Notice Some of the material is taken from Object-Oriented Software Construction, 2nd edition, by Bertrand Meyer (Prentice.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Lecture 7: References and Assignment.
Chair of Software Engineering OOSC - Summer Semester Object-Oriented Software Construction Bertrand Meyer Lecture 3: Abstract Data Types.
COMPSCI 105 S Principles of Computer Science 12 Abstract Data Type.
Chair of Software Engineering OOSC - Summer Semester Object-Oriented Software Construction Bertrand Meyer.
Chair of Software Engineering OOSC - Summer Semester Object-Oriented Software Construction Bertrand Meyer.
Chair of Software Engineering OOSC - Summer Semester Object-Oriented Software Construction Bertrand Meyer.
Chair of Software Engineering OOSC Summer Semester Object-Oriented Software Construction Bertrand Meyer.
Chair of Software Engineering OOSC - Summer Semester Object-Oriented Software Construction Bertrand Meyer.
Chair of Software Engineering OOSC - Summer Semester Bertrand Meyer Object-Oriented Software Construction Lecture 8: More on inheritance.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Lecture 17: Topological Sort Algorithm.
Chair of Software Engineering OOSC - Summer Semester Object-Oriented Software Construction Bertrand Meyer.
Chair of Software Engineering OOSC - Summer Semester Object-Oriented Software Construction Bertrand Meyer Lecture 10: Project Presentation Ilinca.
Chair of Software Engineering OOSC - Summer Semester Object-Oriented Software Construction Bertrand Meyer Lecture 20: Some design principles.
Chair of Software Engineering ATOT - Lecture 12, 12 May Advanced Topics in Object Technology Bertrand Meyer.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Lecture 4: The Interface of a Class.
Chair of Software Engineering OOSC - Summer Semester Object-Oriented Software Construction Bertrand Meyer Lecture 12: Design by Contract™
Chair of Software Engineering ATOT - Lecture 8, 28 April Advanced Topics in Object Technology Bertrand Meyer.
Chair of Software Engineering OOSC Summer Semester Object-Oriented Software Construction Bertrand Meyer.
Chair of Software Engineering OOSC - Summer Semester Object-Oriented Software Construction Bertrand Meyer.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Lecture 4: The Interface of a Class.
Chair of Software Engineering ATOT - Lecture 11, 7 May Advanced Topics in Object Technology Bertrand Meyer.
Chair of Software Engineering OOSC - Summer Semester Object-Oriented Software Construction Bertrand Meyer Lecture 6: Genericity.
Chair of Software Engineering ATOT - Lecture 3, 7 April Advanced Topics in Object Technology Bertrand Meyer.
Chair of Software Engineering ATOT - Lecture 14, 19 May Advanced Topics in Object Technology Bertrand Meyer.
CHAPTER 6 Stacks. 2 A stack is a linear collection whose elements are added and removed from one end The last element to be put on the stack is the first.
1 Introduction to: Design by Contract Fall 2005 OOPD John Anthony.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Exercise Session 10.
1 ES 314 Advanced Programming Lec 2 Sept 3 Goals: Complete the discussion of problem Review of C++ Object-oriented design Arrays and pointers.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Exercise Session 7.
Chair of Software Engineering ATOT - Lecture 7, 23 April Advanced Topics in Object Technology Bertrand Meyer.
Chair of Software Engineering OOSC - Summer Semester Object-Oriented Software Construction Bertrand Meyer.
C++ fundamentals.
1 Genericity Parameterizing by Type. 2 Generic Class One that is parameterized by type  Works when feature semantics is common to a set of types On object.
Design Patterns OOD. Course topics Design Principles UML –Class Diagrams –Sequence Diagrams Design Patterns C#,.NET (all the course examples) Design Principles.
CSCI-383 Object-Oriented Programming & Design Lecture 4.
© Bertrand Meyer and Yishai Feldman Notice Some of the material is taken from Object-Oriented Software Construction, 2nd edition, by Bertrand Meyer (Prentice.
Ceg860 (Prasad)L6MR1 Modularity Extendibility Reusability.
Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical.
CSE-C1 Algs & DS 1 CSE–C1 Algorithms and Data Structures 1 lecturer Dr.Matthew Montebello office CB 409 credit 1 lectures 10.
Stephenson College DP 96 1 Object-Orientation by Derek Peacock.
Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical.
OBJECT-ORIENTED PROGRAMMING (OOP) WITH C++ Instructor: Dr. Hany H. Ammar Dept. of Electrical and Computer Engineering, WVU.
MT311 Java Application Development and Programming Languages Li Tak Sing( 李德成 )
Understanding Data Types and Collections Lesson 2.
SOFTWARE DESIGN. INTRODUCTION There are 3 distinct types of activities in design 1.External design 2.Architectural design 3.Detailed design Architectural.
Data Abstaraction Chapter 10.
Abstraction ADTs, Information Hiding and Encapsulation.
Chapter 10, Slide 1 ABSTRACT DATA TYPES Based on the fundamental concept of ABSTRACTION:  process abstraction  data abstraction Both provide:  information.
© 2006 Pearson Addison-Wesley. All rights reserved 2-1 Chapter 2 Principles of Programming & Software Engineering.
Specifying an ADT Give function specification. Identify partial functions A function which cannot be applied on all of its possible parameters Categorize.
ANU COMP2110 Software Design in 2003 Lecture 10Slide 1 COMP2110 Software Design in 2004 Lecture 12 Documenting Detailed Design How to write down detailed.
Principles of programming languages 10: Object oriented languages Isao Sasano Department of Information Science and Engineering.
(1) ICS 313: Programming Language Theory Chapter 11: Abstract Data Types (Data Abstraction)
Requirements Engineering Methods for Requirements Engineering Lecture-31.
Object-Oriented Design Concepts University of Sunderland.
DBC NOTES. Design By Contract l A contract carries mutual obligations and benefits. l The client should only call a routine when the routine’s pre-condition.
Object Design More Design Patterns Object Constraint Language Object Design Specifying Interfaces Review Exam 2 CEN 4010 Class 18 – 11/03.
Lecture 2 Intro. To Software Engineering and Object-Oriented Programming (2/2)
CSC 243 – Java Programming, Spring, 2014 Week 4, Interfaces, Derived Classes, and Abstract Classes.
© Bertrand Meyer and Yishai Feldman Notice Some of the material is taken from Object-Oriented Software Construction, 2nd edition, by Bertrand Meyer (Prentice.
Design by Contract Jim Fawcett CSE784 – Software Studio
Design by Contract Jim Fawcett CSE784 – Software Studio
Lecture 2 of Computer Science II
Stack ADT & Modularity 2 implementations of the Stack abstract data type: Array Linked List Program design: modularity, abstraction and information hiding.
Introduction to Data Structure
Algebraic Specification Software Specification Lecture 34
Software Architecture Prof. Dr. Bertrand Meyer
Presentation transcript:

Chair of Software Engineering OOSC - Lecture 4 1 Object-Oriented Software Construction Bertrand Meyer

Chair of Software Engineering OOSC - Lecture 4 2 Reading assignment  OOSC2  Chapter 10: Genericity

Chair of Software Engineering OOSC - Lecture 4 3 Lecture 4: Abstract Data Types

Chair of Software Engineering OOSC - Lecture 4 4 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

Chair of Software Engineering OOSC - Lecture 4 5 The first step  A system performs certain actions on certain data.  Basic duality:  Functions [or: Operations, Actions]  Objects [or: Data] Action Object Processor

Chair of Software Engineering OOSC - Lecture 4 6 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

Chair of Software Engineering OOSC - Lecture 4 7 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

Chair of Software Engineering OOSC - Lecture 4 8 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 objects they manipulate — not on “the” function they achieve.

Chair of Software Engineering OOSC - Lecture 4 9 The O-O designer’s motto  Ask NOT first WHAT the system does: Ask WHAT it does it TO!

Chair of Software Engineering OOSC - Lecture 4 10 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.

Chair of Software Engineering OOSC - Lecture 4 11 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

Chair of Software Engineering OOSC - Lecture 4 12 The theoretical basis  The main issue: How to describe program objects (data structures):  Completely  Unambiguously  Without overspecifying?  (Remember information hiding)

Chair of Software Engineering OOSC - Lecture 4 13 A stack, concrete object count representation (array_up) capacity representation [count] := x free (array_down) 1 representation n new (linked) item previous item previous “Push” operation: count := count + 1 representation [free] := x “Push” operation: free := free - 1 new (n) n.item := x “Push” operation: n.previous := last head := n

Chair of Software Engineering OOSC - Lecture 4 14 A stack, concrete object count representation (array_up) capacity representation [count] := x free (array_down) 1 representation n new (linked) item previous item previous “Push” operation: count := count + 1 representation [free] := x “Push” operation: free := free - 1 new (n) n.item := x “Push” operation: n.previous := last head := n

Chair of Software Engineering OOSC - Lecture 4 15 Stack: An abstract data type  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 OOSC - Lecture 4 16 Using functions to model operations put,= () sxs’

Chair of Software Engineering OOSC - Lecture 4 17 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

Chair of Software Engineering OOSC - Lecture 4 18 The STACK ADT (cont’d)  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 (,) = sxs’

Chair of Software Engineering OOSC - Lecture 4 19 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.

Chair of Software Engineering OOSC - Lecture 4 20 Formal stack expressions value = item (remove (put (remove (put (put (remove (put (put (put (new, x8), x7), x6)), item (remove (put (put (new, x5), x4)))), x2)), x1)))

Chair of Software Engineering OOSC - Lecture 4 21 Expressed differently  s1 = new  s2 = put (put (put (s1, x8), x7), x6)  s3 = remove (s2)  s4 = new  s5 = put (put (s4, x5), x4)  s6 = remove (s5)  y1 = item (s6)  s7 = put (s3, y1)  s8 = put (s7, x2)  s9 = remove (s8)  s10 = put (s9, x1)  s11 = remove (s10)  value = item (s11) value = item (remove (put (remove (put (put (remove (put (put (put (new, x8), x7), x6)), item (remove (put (put (new, x5), x4)))), x2)), x1)))

Chair of Software Engineering OOSC - Lecture 4 22 Expression reduction (1/10) value = item ( remove ( put ( remove ( put ( remove ( put (put (put (new, x8), x7), x6) ), item ( remove ( put (put (new, x5), x4) ), x2) ), x1) ) x7 x8 x6 x5 x4 Stack 1Stack 2

Chair of Software Engineering OOSC - Lecture 4 23 Expression reduction (2/10) x7 put remove x8 x7 x8 x7 x8 x6 value = item ( remove ( put ( remove ( put ( remove ( put (put (put (new, x8), x7), x6) ), item ( remove ( put (put (new, x5), x4) ), x2) ), x1) ) x5 x4 Stack 1Stack 2

Chair of Software Engineering OOSC - Lecture 4 24 Expression reduction (3/10) value = item ( remove ( put ( remove ( put ( remove ( put (put (put (new, x8), x7), x6) ), item ( remove ( put (put (new, x5), x4) ), x2) ), x1) ) x7 put remove x8 x7 x8 x7 x8 x2 x7 put remove x8 x7 x8 x7 x8 x2 Stack 1 x5 x4 Stack 2

Chair of Software Engineering OOSC - Lecture 4 25 Expression reduction (4/10) value = item ( remove ( put ( remove ( put ( remove ( put (put (put (new, x8), x7), x6) ), item ( remove ( put (put (new, x5), x4) ), x2) ), x1) ) x5 put remove x5 x4 x7 x8 x7 x8 Stack 1Stack 2

Chair of Software Engineering OOSC - Lecture 4 26 Expression reduction (5/10) value = item ( remove ( put ( remove ( put ( remove ( put (put (put (new, x8), x7), x6) ), item ( remove ( put (put (new, x5), x4) ), x2) ), x1) ) item x5 Stack 2 x7 x8 x7 x8 Stack 1

Chair of Software Engineering OOSC - Lecture 4 27 value = item ( remove ( put ( remove ( put ( remove ( put (put (put (new, x8), x7), x6) ), item ( remove ( put (put (new, x5), x4) ), x2) ), x1) ) Expression reduction (6/10) x5 Stack 2 x7 x8 x7 x8 Stack 1

Chair of Software Engineering OOSC - Lecture 4 28 value = item ( remove ( put ( remove ( put ( remove ( put (put (put (new, x8), x7), x6) ), item ( remove ( put (put (new, x5), x4) ), x2) ), x1) ) Expression reduction (7/10) x5 x7 x8 x7 x8 Stack 3

Chair of Software Engineering OOSC - Lecture 4 29 Expression reduction (8/10) value = item ( remove ( put ( remove ( put ( remove ( put (put (put (new, x8), x7), x6) ), item ( remove ( put (put (new, x5), x4) ), x2) ), x1) ) x5 x7 x8 x7 x8 Stack 3 put remove x1 x5 x7 x8 x7 x8 x5 x7 x8 x7 x8

Chair of Software Engineering OOSC - Lecture 4 30 Expression reduction (9/10) item x5 x7 x8 x7 x8 Stack 3 value = item ( remove ( put ( remove ( put ( remove ( put (put (put (new, x8), x7), x6) ), item ( remove ( put (put (new, x5), x4) ), x2) ), x1) )

Chair of Software Engineering OOSC - Lecture 4 31 Expression reduction (10/10) value = item ( remove ( put ( remove ( put ( remove ( put (put (put (new, x8), x7), x6) ), item ( remove ( put (put (new, x5), x4) ), x2) ), x1) ) value = x5 x5 x7 x8 x7 x8 Stack 3

Chair of Software Engineering OOSC - Lecture 4 32 Expressed differently  s1 = new  s2 = put (put (put (s1, x8), x7), x6)  s3 = remove (s2)  s4 = new  s5 = put (put (s4, x5), x4)  s6 = remove (s5)  y1 = item (s6)  s7 = put (s3, y1)  s8 = put (s7, x2)  s9 = remove (s8)  s10 = put (s9, x1)  s11 = remove (s10)  value = item (s11) value = item (remove (put (remove (put (put (remove (put (put (put (new, x8), x7), x6)), item (remove (put (put (new, x5), x4)))), x2)), x1)))

Chair of Software Engineering OOSC - Lecture 4 33 An operational view of the expression value = item (remove (put (remove (put (put (remove (put (put (put (new, x8), x7), x6)), item (remove (put (put (new, x5), x4)))), x2)), x1))) x8 x7 x6 x8 x7 s2s3 (empty) s1 x5 x4 s5 (empty) s4 x5 s6 y1 x8 x7 x5 s7 (s9, s11) x8 x7 x5 s8 x2 x8 x7 x5 s10 x1

Chair of Software Engineering OOSC - Lecture 4 34 Sufficient completeness  Three forms of functions in the specification of an ADT T:  Creators: OTHER  T e.g. new  Queries: T ...  OTHERe.g. item, empty  Commands: T ...  T e.g. put, remove  Sufficiently complete specification: a “Query Expression” of the form: f (...) where f is a query, may be reduced through application of the axioms to a form not involving T

Chair of Software Engineering OOSC - Lecture 4 35 Stack: An abstract data type  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 OOSC - Lecture 4 36 ADT and software architecture  Abstract data types provide an ideal basis for modularizing software.  Identify every module with an implementation of an abstract data type, i.e. the description of a set of objects with a common interface.  The interface is defined by a set of operations (implementing the functions of the ADT) constrained by abstract properties (the axioms and preconditions).  The module consists of a representation for the abstract data type and an implementation for each of the operations. Auxiliary operations may also be included.

Chair of Software Engineering OOSC - Lecture 4 37 Implementing an ADT  Three components: (E1)The ADT’s specification: functions, axioms, preconditions. (Example: stacks.) (E2)Some representation choice. (Example:.) (E3)A set of subprograms (routines) and attributes, each implementing one of the functions of the ADT specification (E1) in terms of the chosen representation (E2). (Example: routines put, remove, item, empty, new.)

Chair of Software Engineering OOSC - Lecture 4 38 A choice of stack representation count representation (array_up) capacity “Push” operation: count := count + 1 representation [count] := x

Chair of Software Engineering OOSC - Lecture 4 39 Application to information hiding Secret part: Choice of representation (E2) Implementation of functions by features (E3) ADT specification (E1) Public part:

Chair of Software Engineering OOSC - Lecture 4 40 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 objects they manipulate — not on “the” function they achieve.

Chair of Software Engineering OOSC - Lecture 4 41 Object technology: More precise definition  Object-oriented software construction is the construction of software systems as structured collections of (possibly partial) abstract data type implementations.

Chair of Software Engineering OOSC - Lecture 4 42 Classes: The fundamental structure  Merging of the notions of module and type:  Module = Unit of decomposition: set of services  Type = Description of a set of run-time objects (“instances” of the type)  The connection:  The services offered by the class, viewed as a module, are the operations available on the instances of the class, viewed as a type.

Chair of Software Engineering OOSC - Lecture 4 43 Class relations  Two relations:  Client  Heir

Chair of Software Engineering OOSC - Lecture 4 44 Overall system structure CHUNK word_count justified? add_word remove_word justify unjustify length font FIGURE PARAGRAPHWORD space_before space_after add_space_before add_space_after set_font hyphenate_on hyphenate_off QUERIESCOMMANDS FEATURES Inheritance Client

Chair of Software Engineering OOSC - Lecture 4 45 A very deferred class deferred class COUNTER feature item: INTEGER is deferred end -- Counter value up is -- Increase item by 1. deferred ensure item = old item + 1 end down is -- Decrease item by 1. deferred ensure item = old item – 1 end invariant item >= 0 end

Chair of Software Engineering OOSC - Lecture 4 46 End of lecture 4