115
1 On Understanding Data Abstraction ... Revisited 1

On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Page 1: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

1

On UnderstandingData Abstraction

...Revisited

1

Page 2: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

2

William R. CookThe University

of Texas at Austin

Dedicated to P. Wegner

2

Page 3: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

3

Objects

????

Abstract Data Types

3

Page 4: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

4

Warnings!

4

Page 5: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

5

No “Objects Model the Real World”

5

Page 6: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

6

No Inheritance

6

Page 7: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

7

No Mutable State

7

Page 8: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

8

No Subtyping!

8

Page 9: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

9

Interfacesas types

9

Page 10: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

10

NotEssential

(very nice but not essential)

10

Page 11: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

[ ]11

discussinheritance

later

11

Page 12: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

12

Abstraction

12

Page 13: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

13

13

Page 14: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

Hidden

Visible

14

14

Page 15: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

15

ProceduralAbstraction

bool f(int x) { … }

15

Page 16: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

16

ProceduralAbstraction

int → bool

16

Page 17: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

17

(one kind of)Type

Abstraction

∀T.Set[T]

17

Page 18: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

18

Abstract Data Type

signature Set empty! ! : Set insert! ! : Set, Int → Set isEmpty! ! : Set → Bool contains!! : Set, Int → Bool

18

Page 19: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

Abstract

19

Abstract Data Type

signature Set empty! ! : Set insert! ! : Set, Int → Set isEmpty! ! : Set → Bool contains!! : Set, Int → Bool

19

Page 20: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

20

Type+

Operations

20

Page 21: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

21

ADT Implementation

abstype Set = List of Int empty! ! ! = [] insert(s, n) ! = (n : s) isEmpty(s)! ! = (s == []) contains(s, n) ! = (n ∈ s)

21

Page 22: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

22

Using ADT valuesdef x:Set = emptydef y:Set = insert(x, 3)def z:Set = insert(y, 5)print( contains(z, 2) )==> false

22

Page 23: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

23

23

Page 24: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

Hiddenrepresentation:

List of Int

Visible name: Set

24

24

Page 25: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

25

ISetModule = ∃Set.{ empty! ! : Set insert! ! : Set, Int → Set isEmpty! : Set → Bool contains! : Set, Int → Bool}

25

Page 26: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

26

Natural!

26

Page 27: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

27

just likebuilt-in types

27

Page 28: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

28

MathematicalAbstract Algebra

28

Page 29: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

29

Type Theory

∃x.P(existential types)

29

Page 30: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

30

Abstract Data Type

=Data Abstraction

30

Page 31: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

31

Right?

31

Page 32: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

32

S = { 1, 3, 5, 7, 9 }

32

Page 33: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

33

Another way

33

Page 34: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

34

P(n) = even(n) & 1≤n≤9

34

Page 35: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

35

S = { 1, 3, 5, 7, 9 }

P(n) = even(n) & 1≤n≤9

35

Page 36: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

36

Sets ascharacteristic

functions

36

Page 37: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

37

type Set = Int → Bool

37

Page 38: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

38

Empty =

λn. false

38

Page 39: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

39

Insert(s, m) =

λn. (n=m) ∨ s(n)

39

Page 40: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

40

Using them is easydef x:Set = Emptydef y:Set = Insert(x, 3)def z:Set = Insert(y, 5)print( z(2) ) ==> false

40

Page 41: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

41

So What?

41

Page 42: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

42

Flexibility

42

Page 43: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

43

set of alleven numbers

43

Page 44: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

44

Set ADT:Not Allowed!

44

Page 45: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

45

or… break open ADT

& change representation

45

Page 46: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

46

set of even numbers

as afunction?

46

Page 47: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

47

Even =

λn. (n mod 2 = 0)

47

Page 48: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

48

Even interoperatesdef x:Set = Evendef y:Set = Insert(x, 3)def x:Set = Insert(y, 5)print( z(2) )==> true

48

Page 49: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

49

Sets-as-functionsare

objects!

49

Page 50: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

50

No type abstraction required!

type Set = Int → Bool

50

Page 51: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

51

multiplemethods?

sure...

51

Page 52: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

52

interface Set { contains: Int → Bool isEmpty: Bool}

52

Page 53: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

53

What about Empty and Insert?

(they are classes)

53

Page 54: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

54

class Empty { contains(n) { return false;} isEmpty() { return true;}}

54

Page 55: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

55

class Insert(s, m) { contains(n) { return (n=m) ∨ s.contains(n) } isEmpty() { return false }}

55

Page 56: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

56

Using Classesdef x:Set = Empty()def y:Set = Insert(x, 3)def z:Set = Insert(y, 5)print( z.contains(2) ) ==> false

56

Page 57: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

57

An object is

the set of observations that

can be made upon it

57

Page 58: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

58

Including more methods

58

Page 59: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

59

interface Set { contains! : Int → Bool isEmpty! : Bool insert ! : Int → Set}

59

Page 60: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

TypeRecursion

60

interface Set { contains! : Int → Bool isEmpty! : Bool insert ! : Int → Set}

60

Page 61: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

61

class Empty { contains(n) !{ return false;} isEmpty() ! { return true;} insert(n) ! { return ! ! Insert(this, n);}}

61

Page 62: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

ValueRecursion

62

class Empty { contains(n) !{ return false;} isEmpty() ! { return true;} insert(n) ! { return ! ! Insert(this, n);}}

62

Page 63: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

63

Using objectsdef x:Set = Emptydef y:Set = x.insert(3)def z:Set = y.insert(5)print( z.contains(2) )==> false

63

Page 64: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

64

Autognosis

64

Page 65: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

65

Autognosis

(Self-knowledge)

65

Page 66: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

66

Autognosis

An object can access other objects only through public

interfaces

66

Page 67: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

67

operationson

multiple objects?

67

Page 68: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

68

unionof

two sets

68

Page 69: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

69

class Union(a, b) { contains(n) { a.contains(n) ∨ b.contains(n); } isEmpty() { a.isEmpty(n) ∧ b.isEmpty(n); } ...}

69

Page 70: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

Complex Operation(binary) 70

interface Set { contains: Int → Bool isEmpty: Bool insert! ! : Int → Set union! ! : Set → Set}

70

Page 71: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

71

intersectionof

two sets??

71

Page 72: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

72

class Intersection(a, b) { contains(n) { a.contains(n) ∧ b.contains(n); }

isEmpty() { ? no way! ? } ...}

72

Page 73: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

73

Autognosis:Prevents some operations

(complex ops)

73

Page 74: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

74

Autognosis:Prevents some optimizations(complex ops)

74

Page 75: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

75

Inspecting two representations &

optimizing operations on them are easy

with ADTs

75

Page 76: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

76

Objects are fundamentally different

from ADTs

76

Page 77: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

ADT(existential types)

SetImpl = ∃ Set . { empty : Set

isEmpty : Set → Bool contains : Set, Int → Bool

insert : Set, Int → Set union : Set, Set → Set

}

77

Object Interface(recursive types)

Set = { isEmpty! : Bool contains! : Int → Bool insert! : Int → Set union! : Set → Set}Empty : SetInsert : Set x Int → SetUnion : Set x Set → Set

77

Page 78: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

ss

Empty Insert(s', m)

isEmpty(s) true false

contains(s, n) falsen=m ∨

contains(s', n)

insert(s, n) false Insert(s, n)

union(s, s'') isEmpty(s'') Union(s, s'')

Operations/Observations

78

78

Page 79: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

s

Empty Insert(s', m)

isEmpty(s) true false

contains(s, n) falsen=m ∨

contains(s', n)

insert(s, n) false Insert(s, n)

union(s, s'') isEmpty(s'') Union(s, s'')

79

ADT Organization

79

Page 80: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

s

Empty Insert(s', m)

isEmpty(s) true false

contains(s, n) falsen=m ∨

contains(s', n)

insert(s, n) false Insert(s, n)

union(s, s'') isEmpty(s'') Union(s, s'')

OO Organization

80

80

Page 81: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

81

Objects are fundamental

(too)

81

Page 82: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

82

Mathematicalfunctional

representation of data

82

Page 83: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

83

Type Theoryµx.P

(recursive types)

83

Page 84: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

84

ADTs require a

static type system

84

Page 85: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

85

Objects work wellwith or without static typing

85

Page 86: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

86

“Binary” Operations?

Stack, Socket, Window, Service, DOM, Enterprise

Data, ...

86

Page 87: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

87

Objects arevery

higher-order(functions passed as data and

returned as results)

87

Page 88: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

88

Verification

88

Page 89: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

89

ADTs: construction

Objects: observation

89

Page 90: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

90

ADTs: induction

Objects: coinductioncomplicated by: callbacks,

state

90

Page 91: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

91

Objects are designed to be as difficult as possible to verify

91

Page 92: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

92

Simulation

One object can simulate another!(identity is bad)

92

Page 93: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

93

Java

93

Page 94: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

94

What is a type?

94

Page 95: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

95

Declare variables

Classify values

95

Page 96: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

96

Class as type

=> representation

96

Page 97: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

97

Class as type

=> ADT

97

Page 98: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

98

Interfaces as type

=> behavior pure objects

98

Page 99: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

99

Harmful!

instanceof Class(Class) expClass x;

99

Page 100: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

100

Object-Oriented subset of Java:class name used only after “new”

100

Page 101: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

101

It’s not an accident that “int” is an ADT

in Java

101

Page 102: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

102

Smalltalk

102

Page 103: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

103

class True ifTrue: a ifFalse: b ^a

class False ifTrue: a ifFalse: b ^b

103

Page 104: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

104

True = λ a . λ b . a

False = λ a . λ b . b

104

Page 105: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

105

Inheritance(in one slide)

105

Page 106: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

106

AObject

Y(G)

G

Self-reference

Δ(A)AΔ

Modification

Δ(Y(G))GΔ

Y(ΔoG)

GΔInheritance Δ(Y(G))

106

Inheritance

106

Page 107: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

107

107

History

107

Page 108: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

108

108

User-defined types and

procedural data structures

as complementary approaches to

data abstraction

by J. C. Reynolds

New Advances in Algorithmic

Languages INRIA, 108

Page 109: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

objects

Abstract data types User-defined types and

procedural data structures

as complementary approaches to

data abstraction

by J. C. Reynolds

New Advances in Algorithmic Languages

INRIA, 1975109

109

Page 110: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

110

110

“[an object with two methods] is more a tour de force than a specimen of clear programming.”

- J. Reynolds

110

Page 111: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

111

Extensibility Problem(aka Expression Problem)

111

1975 Discovered by J. Reynolds1990 Elaborated by W. Cook1998 Renamed by P. Wadler2005 Solved by M. Odersky (?)2025 Widely understood (?)

111

Page 112: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

112

Summary

112

Page 113: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

113

It is possible to do Object-Oriented

programming in Java

113

Page 114: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

114

Lambda-calculuswas the first object-oriented language (1941)

114

Page 115: On Understanding Data Abstraction Revisitedweb.cecs.pdx.edu/~black/OOP/slides/Cook on DataAbstraction.pdf · built-in types 27. 28 Mathematical Abstract Algebra 28. 29 Type Theory

115

Data Abstraction

/ \  ADT Objects

115