33
Carlos D. Rivera February 28, 2007 Design-by-Contract Design-by-Contract

Carlos D. Rivera February 28, 2007 Design-by-Contract

Embed Size (px)

Citation preview

Page 1: Carlos D. Rivera February 28, 2007 Design-by-Contract

Carlos D. RiveraFebruary 28, 2007

Design-by-ContractDesign-by-Contract

Page 2: Carlos D. Rivera February 28, 2007 Design-by-Contract

WHAT ?

Design-by-Contract (DBC) is a methodology for designing

computer software.

Page 3: Carlos D. Rivera February 28, 2007 Design-by-Contract

WHAT ?

Design-by-Contract (DBC) is a methodology for designing

computer software.

• Define checkable interface specifications

Page 4: Carlos D. Rivera February 28, 2007 Design-by-Contract

WHAT ?

Design-by-Contract (DBC) is a methodology for designing

computer software.

• Define checkable interface specifications

• Theory of abstract data types (e.g., interfaces)

Page 5: Carlos D. Rivera February 28, 2007 Design-by-Contract

WHAT ?

Design-by-Contract (DBC) is a methodology for designing

computer software.

• Define checkable interface specifications

• Theory of abstract data types (e.g., interfaces)

• Metaphor of business contract (e.g., pre-, post-)

Page 6: Carlos D. Rivera February 28, 2007 Design-by-Contract

HISTORY

Bertrand Meyer

Page 7: Carlos D. Rivera February 28, 2007 Design-by-Contract

HISTORY

Bertrand Meyer

• Eiffel

Page 8: Carlos D. Rivera February 28, 2007 Design-by-Contract

HISTORY

Bertrand Meyer

• Eiffel

• Object-Oriented Software Construction

Page 9: Carlos D. Rivera February 28, 2007 Design-by-Contract

HISTORY

Bertrand Meyer

• Eiffel

• Object-Oriented Software Construction

• DBC circa 1986

Page 10: Carlos D. Rivera February 28, 2007 Design-by-Contract

INTRODUCTION

Design-by-Contract is a thinly veiled mathematical proof.

Page 11: Carlos D. Rivera February 28, 2007 Design-by-Contract

FOUNDATIONDesign-by-Contract :

Page 12: Carlos D. Rivera February 28, 2007 Design-by-Contract

FOUNDATION

1. Abstract Mathematical Models of a System• “this phenomena can be represented by

this mathematical language”

Design-by-Contract :

Page 13: Carlos D. Rivera February 28, 2007 Design-by-Contract

FOUNDATION

1. Abstract Mathematical Models of a System• “this phenomena can be represented by

this mathematical language”

2. Formal Specification• “this mathematical model will produce this, always”

Design-by-Contract :

Page 14: Carlos D. Rivera February 28, 2007 Design-by-Contract

FOUNDATION

1. Abstract Mathematical Models of a System• “this phenomena can be represented by

this mathematical language”

2. Formal Specification• “this mathematical model will produce this, always”

3. Formal Verification• “we can check if the specification is true

for every case”

Design-by-Contract :

Page 15: Carlos D. Rivera February 28, 2007 Design-by-Contract

OVERVIEW

Object-oriented process commonly implementedusing assertions.

Page 16: Carlos D. Rivera February 28, 2007 Design-by-Contract

OVERVIEW

Object-oriented process commonly implementedusing assertions.

Assertion benefits:

Page 17: Carlos D. Rivera February 28, 2007 Design-by-Contract

OVERVIEW

Object-oriented process commonly implementedusing assertions.

Assertion benefits:

• Program correctness/testing

Page 18: Carlos D. Rivera February 28, 2007 Design-by-Contract

OVERVIEW

Object-oriented process commonly implementedusing assertions.

Assertion benefits:

• Program correctness/testing

• On/off during development

Page 19: Carlos D. Rivera February 28, 2007 Design-by-Contract

WHY ?

Benefits of DBC :

Page 20: Carlos D. Rivera February 28, 2007 Design-by-Contract

WHY ?

1. Clear design process

Benefits of DBC :

Page 21: Carlos D. Rivera February 28, 2007 Design-by-Contract

WHY ?

1. Clear design process

2. Inheritance

Benefits of DBC :

Page 22: Carlos D. Rivera February 28, 2007 Design-by-Contract

WHY ?

1. Clear design process

2. Inheritance

3. Exception handling

Benefits of DBC :

Page 23: Carlos D. Rivera February 28, 2007 Design-by-Contract

WHY ?

1. Clear design process

2. Inheritance

3. Exception handling

4. Automatic software documentation

Benefits of DBC :

Page 24: Carlos D. Rivera February 28, 2007 Design-by-Contract

HOW ?

Client-Supplier business relationships.

Page 25: Carlos D. Rivera February 28, 2007 Design-by-Contract

HOW ?

Client-Supplier business relationships.

Basis: Pre-condition

If you have the right amount of money

If input values within specified range

Expectations

Page 26: Carlos D. Rivera February 28, 2007 Design-by-Contract

HOW ?

Basis: Post-condition

You will get this product

It will be transformed to this result

Guaranteed

Client-Supplier business relationships.

Page 27: Carlos D. Rivera February 28, 2007 Design-by-Contract

HOW ?

Basis: Class Invariant

Under these conditions

Object analysis invariant { assert ( ); }

Maintain

Client-Supplier business relationships.

Page 28: Carlos D. Rivera February 28, 2007 Design-by-Contract

CONCLUSION

Analogy :

Page 29: Carlos D. Rivera February 28, 2007 Design-by-Contract

CONCLUSION

Analogy :

Molds can be used to make copies of objects with negligible variation.

Page 30: Carlos D. Rivera February 28, 2007 Design-by-Contract

CONCLUSION

Analogy :

Molds can be used to make copies of objects with negligible variation.

Assertions can be used to create validated clones of ADTs of precise definition.

Page 31: Carlos D. Rivera February 28, 2007 Design-by-Contract

CONCLUSIONEven though Design-by-Contract may seem

straight-forward and almost routinely basic,

its importance lies in its power to create a

type of mutually agreed upon business

contract, equally understandable to both the

client and developer, that scientifically maps

a problem-solving mathematical model to the

client’s needs.

Page 32: Carlos D. Rivera February 28, 2007 Design-by-Contract

CONCLUSION

Most importantly, the documentation provided

by DBC creates a contract whereby

requirements can be specified and met

without avail.

Page 33: Carlos D. Rivera February 28, 2007 Design-by-Contract

CONCLUSION

Most importantly, the documentation provided

by DBC creates a contract whereby

requirements can be specified and met

without avail.

Questions, Concerns, Complaints ?