on understanding data abstraction revisited
play

On Understanding Data Abstraction ... Revisited 1 1 William R. - PowerPoint PPT Presentation

On Understanding Data Abstraction ... Revisited 1 1 William R. Cook The University of Texas at Austin Dedicated to P. Wegner 2 2 Objects ???? Abstract Data Types 3 3 Warnings! 4 4 No Objects Model the Real World 5 5 No


  1. On Understanding Data Abstraction ... Revisited 1 1

  2. William R. Cook The University of Texas at Austin Dedicated to P. Wegner 2 2

  3. Objects ???? Abstract Data Types 3 3

  4. Warnings! 4 4

  5. No “Objects Model the Real World” 5 5

  6. No Inheritance 6 6

  7. No Mutable State 7 7

  8. No Subtyping! 8 8

  9. Interfaces as types 9 9

  10. Not Essential (very nice but not essential) 10 10

  11. ] [ discuss inheritance later 11 11

  12. Abstraction 12 12

  13. 13 13

  14. Visible Hidden 14 14

  15. Procedural Abstraction bool f(int x) { … } 15 15

  16. Procedural Abstraction int → bool 16 16

  17. (one kind of) Type Abstraction ∀ T.Set[T] 17 17

  18. Abstract Data Type signature Set empty � � : Set insert � � : Set, Int → Set isEmpty �� : Set → Bool contains �� : Set, Int → Bool 18 18

  19. Abstract Data Type Abstract signature Set empty � � : Set insert � � : Set, Int → Set isEmpty �� : Set → Bool contains �� : Set, Int → Bool 19 19

  20. Type + Operations 20 20

  21. ADT Implementation abstype Set = List of Int empty � � � = [] insert(s, n) � = (n : s) isEmpty(s) � � = (s == []) contains(s, n) � = (n ∈ s) 21 21

  22. Using ADT values def x:Set = empty def y:Set = insert(x, 3) def z:Set = insert(y, 5) print( contains(z, 2) )==> false 22 22

  23. 23 23

  24. Visible name: Set Hidden representation: List of Int 24 24

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

  26. Natural! 26 26

  27. just like built-in types 27 27

  28. Mathematical Abstract Algebra 28 28

  29. Type Theory ∃ x.P (existential types) 29 29

  30. Abstract Data Type = Data Abstraction 30 30

  31. Right? 31 31

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

  33. Another way 33 33

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

  35. S = { 1, 3, 5, 7, 9 } P( n ) = even( n ) & 1 ≤ n ≤ 9 35 35

  36. Sets as characteristic functions 36 36

  37. type Set = Int → Bool 37 37

  38. Empty = λ n. false 38 38

  39. Insert(s, m) = λ n. (n=m) ∨ s(n) 39 39

  40. Using them is easy def x:Set = Empty def y:Set = Insert(x, 3) def z:Set = Insert(y, 5) print( z(2) ) ==> false 40 40

  41. So What? 41 41

  42. Flexibility 42 42

  43. set of all even numbers 43 43

  44. Set ADT: Not Allowed! 44 44

  45. or… break open ADT & change representation 45 45

  46. set of even numbers as a function? 46 46

  47. Even = λ n. (n mod 2 = 0) 47 47

  48. Even interoperates def x:Set = Even def y:Set = Insert(x, 3) def x:Set = Insert(y, 5) print( z(2) ) ==> true 48 48

  49. Sets-as-functions are objects! 49 49

  50. No type abstraction required! type Set = Int → Bool 50 50

  51. multiple methods? sure... 51 51

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

  53. What about Empty and Insert ? (they are classes) 53 53

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

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

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

  57. An object is the set of observations that can be made upon it 57 57

  58. Including more methods 58 58

  59. interface Set { contains � : Int → Bool isEmpty � : Bool insert � : Int → Set } 59 59

  60. interface Set { contains � : Int → Bool isEmpty � : Bool insert � : Int → Set } Type Recursion 60 60

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

  62. class Empty { contains(n) � { return false;} isEmpty() � { return true;} insert(n) � { return � � Insert(this, n);} } Value Recursion 62 62

  63. Using objects def x:Set = Empty def y:Set = x.insert(3) def z:Set = y.insert(5) print( z.contains(2) )==> false 63 63

  64. Autognosis 64 64

  65. Autognosis (Self-knowledge) 65 65

  66. Autognosis An object can access other objects only through public interfaces 66 66

  67. operations on multiple objects? 67 67

  68. union of two sets 68 68

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

  70. interface Set { contains: Int → Bool isEmpty: Bool insert � � : Int → Set union � � : Set → Set } Complex Operation (binary) 70 70

  71. intersection of two sets ?? 71 71

  72. class Intersection(a, b) { contains(n) { a.contains(n) ∧ b.contains(n); } isEmpty() { ? no way! ? } ... } 72 72

  73. Autognosis: Prevents some operations (complex ops) 73 73

  74. Autognosis: Prevents some optimizations (complex ops) 74 74

  75. Inspecting two representations & optimizing operations on them are easy with ADTs 75 75

  76. Objects are fundamentally different from ADTs 76 76

  77. ADT Object Interface (existential types) (recursive types) SetImpl = ∃ Set . { Set = { isEmpty � : Bool empty : Set contains � : Int → Bool isEmpty : Set → Bool insert � : Int → Set contains : Set, Int → Bool union � : Set → Set insert : Set, Int → Set } union : Set, Set → Set Empty : Set } Insert : Set x Int → Set Union : Set x Set → Set 77 77

  78. Operations/Observations s Empty Insert(s', m) isEmpty(s) true false n=m ∨ contains(s, n) false contains(s', n) insert(s, n) false Insert(s, n) union(s, s'') isEmpty(s'') Union(s, s'') 78 78

  79. ADT Organization s Empty Insert(s', m) isEmpty(s) true false n=m ∨ contains(s, n) false contains(s', n) insert(s, n) false Insert(s, n) union(s, s'') isEmpty(s'') Union(s, s'') 79 79

  80. OO Organization s Empty Insert(s', m) isEmpty(s) true false n=m ∨ contains(s, n) false contains(s', n) insert(s, n) false Insert(s, n) union(s, s'') isEmpty(s'') Union(s, s'') 80 80

  81. Objects are fundamental (too) 81 81

  82. Mathematical functional representation of data 82 82

  83. Type Theory µ x.P ( recursive types) 83 83

  84. ADTs require a static type system 84 84

  85. Objects work well with or without static typing 85 85

  86. “Binary” Operations? Stack, Socket, Window, Service, DOM, Enterprise Data, ... 86 86

  87. Objects are very higher-order (functions passed as data and returned as results) 87 87

  88. Verification 88 88

  89. ADTs: construction Objects: observation 89 89

  90. ADTs: induction Objects: coinduction complicated by: callbacks, state 90 90

  91. Objects are designed to be as difficult as possible to verify 91 91

  92. Simulation One object can simulate another! (identity is bad) 92 92

  93. Java 93 93

  94. What is a type? 94 94

  95. Declare variables Classify values 95 95

  96. Class as type => representation 96 96

  97. Class as type => ADT 97 97

  98. Interfaces as type => behavior pure objects 98 98

  99. Harmful! instanceof Class ( Class ) exp Class x; 99 99

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

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