object-oriented software construction

49
OOSC - Summer Semester 2005 1 Chair of Software Engineering Object-Oriented Software Construction Bertrand Meyer Lecture 1: Modularity

Upload: licia

Post on 13-Jan-2016

23 views

Category:

Documents


0 download

DESCRIPTION

Object-Oriented Software Construction. Bertrand Meyer Lecture 1: Modularity. Contact. Chair of Software Engineering: http://se.inf.ethz.ch Course page: http://se.inf.ethz.ch/teaching/ss2005/0250/ Course assistant: Ilinca Ciupa http://se.inf.ethz.ch/people/ciupa. Course objectives. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Object-Oriented Software Construction

OOSC - Summer Semester 2005

1

Chair of Software Engineering

Object-Oriented Software Construction

Bertrand Meyer

Lecture 1: Modularity

Page 2: Object-Oriented Software Construction

OOSC - Summer Semester 2005

2

Chair of Software Engineering

Contact

Chair of Software Engineering: http://se.inf.ethz.ch

Course page: http://se.inf.ethz.ch/teaching/ss2005/0250/

Course assistant: Ilinca Ciupa http://se.inf.ethz.ch/people/ciupa

Page 3: Object-Oriented Software Construction

OOSC - Summer Semester 2005

3

Chair of Software Engineering

Course objectives

Provide you with solid knowledge of: Object technology principles and methods The practice of object-oriented analysis, design

and implementation Some open issues Some recent developments A specific technology

Page 4: Object-Oriented Software Construction

OOSC - Summer Semester 2005

4

Chair of Software Engineering

Grading

60% project

40% exam (last lecture day of semester)

Note: no out-of-semester exam

Page 5: Object-Oriented Software Construction

OOSC - Summer Semester 2005

5

Chair of Software Engineering

The project

Theme An Object Spyglass

Documentation User guide: how to use the tool Developer guide: description of the architecture,

main classes, limitations, how to extend the tool

Test suite Thorough set of test cases

Page 6: Object-Oriented Software Construction

OOSC - Summer Semester 2005

6

Chair of Software Engineering

Grading criteria

Design (30 points) Soundness (5 points) Extendibility (5 points) Ease of use (5 points) Minimal requirements (15 points)

Quality of contracts (20 points) Documentation (20 points)

User guide (10 points) Developer guide (10 points)

Test (10 points) Quality of test suite (5 points) Correctness of the tool (5 points)

Quality of code (10 points) Style guidelines (5 points) Quality of code (5 points)

Effort devoted to the project (10 points)

Page 7: Object-Oriented Software Construction

OOSC - Summer Semester 2005

7

Chair of Software Engineering

Reading assignment for next week

OOSC, chapters3: Modularity6: Abstract data types

Page 8: Object-Oriented Software Construction

OOSC - Summer Semester 2005

8

Chair of Software Engineering

Some words of warning

Steps in reacting to O-O (from the preface to Object-Oriented Software Construction): “(1) It’s trivial; (2) It’s wrong; (3) That’s how I did it all along anyway.”

Beware of the “mOOzak” phenomenon.

Page 9: Object-Oriented Software Construction

OOSC - Summer Semester 2005

9

Chair of Software Engineering

Some words of warning (cont’d)

benefit_from_course is-- Make students succeed.

requiresome_humility

doall_exercises

ensureOO_mastery_for_fun_and_profit

end

Page 10: Object-Oriented Software Construction

OOSC - Summer Semester 2005

10

Chair of Software Engineering

Terminology

I will be strict about terminology: Endless confusions in the literature and in discussions. Basic concepts have precise definitions — no justification

whatsoever for such confusions. Object technology is (in part) about bringing rational,

scientific principles to software. No excuse for sloppy terminology.

Alternative conventions will be mentioned when necessary.

CHF 5 fine for saying “object” when meaning “class” (after lecture 4)

Page 11: Object-Oriented Software Construction

OOSC - Summer Semester 2005

11

Chair of Software Engineering

Software engineering

The collection of processes, methods, techniques, tools and languages for developing quality operational software.

Page 12: Object-Oriented Software Construction

OOSC - Summer Semester 2005

12

Chair of Software Engineering

External quality factors

Correctness Robustness Security Ease of use Ease of learning Efficiency

Extendibility Reusability Portability

Timeliness Cost-effectiveness

Security

Hostility

Robustness

Errors

Correctness

Specification

Process quality:

Product quality (long-term):

Product quality (immediate):

Page 13: Object-Oriented Software Construction

OOSC - Summer Semester 2005

13

Chair of Software Engineering

Reliability

Correctness:The systems’ ability to perform according to specification, in cases covered by the specification

Robustness:The systems’ ability to perform reasonably in cases not covered by the specification

Security (integrity):The systems’ ability to protect itself against hostile use

Page 14: Object-Oriented Software Construction

OOSC - Summer Semester 2005

14

Chair of Software Engineering

Reliability

Correctness + Robustness + Security

Techniques will be studied in detail: typing, Design by Contract, …

Page 15: Object-Oriented Software Construction

OOSC - Summer Semester 2005

15

Chair of Software Engineering

Modularity

Reusability + Extendibility

Favored by architectural techniques tending to ensure decentralization of modules

Page 16: Object-Oriented Software Construction

OOSC - Summer Semester 2005

16

Chair of Software Engineering

Modularity

Some principles of modularity: Decomposability Composability Continuity Information hiding The open-closed principle The single choice principle

Page 17: Object-Oriented Software Construction

OOSC - Summer Semester 2005

17

Chair of Software Engineering

Decomposability

Method helps decompose complex problems into subproblems.

COROLLARY: Division of labor. Example: Top-down design method (see next). Counter-example: General initialization module.

Page 18: Object-Oriented Software Construction

OOSC - Summer Semester 2005

18

Chair of Software Engineering

Top-down functional design

A

B D C

C1 I1 C2 I2 I

Topmost functional abstraction

Loop Conditional

Sequence

Page 19: Object-Oriented Software Construction

OOSC - Summer Semester 2005

19

Chair of Software Engineering

Top-down design

See Niklaus Wirth, “Program Construction by Stepwise Refinement”, Communications of the ACM, 14, 4, (April 1971), p 221-227.

http://www.acm.org/classics/dec95/

Page 20: Object-Oriented Software Construction

OOSC - Summer Semester 2005

20

Chair of Software Engineering

Method favors production of software elements that may be freely combined with each other to produce new software.

Example: Unix shell conventionsProgram1 | Program2 | Program3

Composability

Page 21: Object-Oriented Software Construction

OOSC - Summer Semester 2005

21

Chair of Software Engineering

Direct mapping

Method yields software systems whose modular structure remains compatible with any modular structure devised in the process of modeling the problem domain.

Page 22: Object-Oriented Software Construction

OOSC - Summer Semester 2005

22

Chair of Software Engineering

Few interfaces principle

Every module communicates with as few others as possible.

(A) (B) (C)

Page 23: Object-Oriented Software Construction

OOSC - Summer Semester 2005

23

Chair of Software Engineering

Small interfaces principle

If two modules communicate, they exchange as little information as possible.

x, y

z

Page 24: Object-Oriented Software Construction

OOSC - Summer Semester 2005

24

Chair of Software Engineering

Explicit interfaces principle

Whenever two modules A and B communicate, this is obvious from the text of A or B or both.

Module A Module B

Data item

x

Modifies Accesses

Page 25: Object-Oriented Software Construction

OOSC - Summer Semester 2005

25

Chair of Software Engineering

Continuity

Method ensures that small changes in specifications yield small changes in architecture.

Design method: Specification Architecture

Example: Principle of Uniform Access (see next)

Counter-example: Programs with patterns after the physical implementation of data structures.

Page 26: Object-Oriented Software Construction

OOSC - Summer Semester 2005

26

Chair of Software Engineering

Uniform Access Principle

Facilities managed by a module are accessible to its clients in the same way whether implemented by computation or by storage.

Definition: A client of a module is any module that uses its facilities.

Page 27: Object-Oriented Software Construction

OOSC - Summer Semester 2005

27

Chair of Software Engineering

Uniform Access: An example

balance = list_of_deposits.total – list_of_withdrawals.total

Ada, Pascal, C/C++, Java, C#: Simula, Eiffel:a.balance a.balancebalance (a) a.balance()

list_of_deposits

list_of_withdrawals

balance

list_of_deposits

list_of_withdrawals

(A2)

(A1)

Page 28: Object-Oriented Software Construction

OOSC - Summer Semester 2005

28

Chair of Software Engineering

Information hiding

Underlying question: how does one “advertise” the capabilities of a module?

Every module should be known to the outside world through an official, “public” interface.

The rest of the module’s properties comprises its “secrets”.

It should be impossible to access the secrets from the outside.

Page 29: Object-Oriented Software Construction

OOSC - Summer Semester 2005

29

Chair of Software Engineering

Information Hiding Principle

The designer of every module must select a subset of the module’s properties as the official information about the module, to be made available to authors of client modules.

Page 30: Object-Oriented Software Construction

OOSC - Summer Semester 2005

30

Chair of Software Engineering

Information hiding

Secret part

Public part

Page 31: Object-Oriented Software Construction

OOSC - Summer Semester 2005

31

Chair of Software Engineering

Information hiding

Justifications: Continuity Decomposability

Page 32: Object-Oriented Software Construction

OOSC - Summer Semester 2005

32

Chair of Software Engineering

The Open-Closed Principle

Modules should be open and closed.

Definitions: Open module: May be extended. Closed module: Usable by clients. May be approved,

baselined and (if program unit) compiled.

The rationales are complementary: For closing a module (manager’s perspective):

Clients need it now. For keeping modules open (developer’s perspective):

One frequently overlooks aspects of the problem.

Page 33: Object-Oriented Software Construction

OOSC - Summer Semester 2005

33

Chair of Software Engineering

An object

start

forth

put_right before after

item index

has an interface

Page 34: Object-Oriented Software Construction

OOSC - Summer Semester 2005

34

Chair of Software Engineering

An object

start

forth

put_right before after

item index

has an implementation

Page 35: Object-Oriented Software Construction

OOSC - Summer Semester 2005

35

Chair of Software Engineering

Information hiding

start

forth

put_right before after

item index

Page 36: Object-Oriented Software Construction

OOSC - Summer Semester 2005

36

Chair of Software Engineering

The Open-Closed principle

F A’

G

H I

A C E

D

B

Page 37: Object-Oriented Software Construction

OOSC - Summer Semester 2005

37

Chair of Software Engineering

Closing modules prematurely

type PUBLICATION =record

author, title: STRING;publication_year: INTEGERcase pubtype: (book, journal, conference) of

book: (publisher: STRING);journal: (editor: STRING);conference: (place, chair: STRING)

endend

Use in clients:

p: PUBLICATION ;case p.pubtype of

book: ... p.publisher ...; journal: ... p.editor ...; conference: ... p.place ...

end

Page 38: Object-Oriented Software Construction

OOSC - Summer Semester 2005

38

Chair of Software Engineering

The Single Choice principle

Whenever a software system must support a set of alternatives, one and only one module in the system should know their exhaustive list.

Editor: set of commands (insert, delete etc.) Graphics system: set of figure types (rectangle,

circle etc.) Compiler: set of language constructs (instruction,

loop, expression etc.)

Page 39: Object-Oriented Software Construction

OOSC - Summer Semester 2005

39

Chair of Software Engineering

Reusability issues

Organizational and managerial issues: (Not covered here.)

Technical issues: what form of components? Routine libraries Packages (Ada) Class libraries What form of classes?

Page 40: Object-Oriented Software Construction

OOSC - Summer Semester 2005

40

Chair of Software Engineering

Reusability: Technical issues

The general pattern for a searching routine:

has (t: TABLE; x: ELEMENT): BOOLEAN is-- Does item x appear in table t?

localpos: POSITION

dofrom

pos := initial_position (t, x) until

exhausted (t, pos) or else found (t, x, pos)

looppos := next (t, x, pos)

endResult := found (t, x, pos)

end

Page 41: Object-Oriented Software Construction

OOSC - Summer Semester 2005

41

Chair of Software Engineering

Issues for a general searching module

Type variation: What are the table elements?

Routine grouping: A searching routine is not enough: it should be

coupled with routines for table creation, insertion, deletion etc.

Implementation variation: Many possible choices of data structures and

algorithms: sequential table (sorted or unsorted), array, binary search tree, file, ...

Page 42: Object-Oriented Software Construction

OOSC - Summer Semester 2005

42

Chair of Software Engineering

Issues

Representation independence:

Can a client request an operation such as table search (has) without knowing what implementation is used internally?

has (t1, y)

Page 43: Object-Oriented Software Construction

OOSC - Summer Semester 2005

43

Chair of Software Engineering

Issues

Factoring out commonality: How can the author of supplier modules take

advantage of commonality within a subset of the possible implementations?

Example: the set of sequential table implementations. A common routine text for has:

has (....; x: T): BOOLEAN is-- Does x appear in the table?

dofrom start until after or else found (x) loop

forthendResult := found (x)

end

Page 44: Object-Oriented Software Construction

OOSC - Summer Semester 2005

44

Chair of Software Engineering

Factoring out commonality

1

item

index

forth

count

start

after

back

before

Page 45: Object-Oriented Software Construction

OOSC - Summer Semester 2005

45

Chair of Software Engineering

Factoring out commonality

TABLE

SEQUENTIAL_TABLE

TREE_TABLE

HASH_TABLE

ARRAY_TABLE

LINKED_TABLE

FILE_TABLE

has

startafterfoundforth

Page 46: Object-Oriented Software Construction

OOSC - Summer Semester 2005

46

Chair of Software Engineering

Implementation variants

Array

Linked list

File

start forth after found (x)

c := first_cell

rewind

i := 1

c := c.right

i := i + 1

read end_of_file

c = Void

f = ξ

c.item = x

i > count t [i] = x

Page 47: Object-Oriented Software Construction

OOSC - Summer Semester 2005

47

Chair of Software Engineering

Encapsulation languages (“Object-based”)

Ada, Modula-2, CLU...

Basic idea: gather a group of routines serving a related purpose, such as has, insert, remove etc., together with the appropriate data structure descriptions.

This addresses the Related Routines issue.

Advantages:

For supplier author: Get everything under one roof. Simplifies configuration management, change of implementation, addition of new primitives.

For client author: Find everything at one place. Simplifies search for existing routines, requests for extensions.

Page 48: Object-Oriented Software Construction

OOSC - Summer Semester 2005

48

Chair of Software Engineering

Complementary material

OOSC2: Chapter 3: Modularity Chapter 4: Approaches to reusability

Page 49: Object-Oriented Software Construction

OOSC - Summer Semester 2005

49

Chair of Software Engineering

End of lecture 1