Chapter 2: Data Abstraction 2'1 Specifying Data via Interfaces - PowerPoint PPT Presentation

1 / 7
About This Presentation
Title:

Chapter 2: Data Abstraction 2'1 Specifying Data via Interfaces

Description:

An Example from Scheme: Nonnegative Integers (define plus (lambda (x y) (if ... (define pred (lambda (n) (- n 1))) Nonnegative Integers: Ordinary implementation ... – PowerPoint PPT presentation

Number of Views:44
Avg rating:3.0/5.0
Slides: 8
Provided by: csW7
Category:

less

Transcript and Presenter's Notes

Title: Chapter 2: Data Abstraction 2'1 Specifying Data via Interfaces


1
Chapter 2 Data Abstraction2.1 Specifying Data
via Interfaces
  • Interface vs. Implementation
  • Interface How the data talks to the outside
    world, a.k.a. client
  • Implementation How the data is represented
    internally
  • Data types like this are said to be abstract.
  • Like Java...

2
public interface Message public void
report(String msg)
public class StdoutMessage implements Message
public void report(String msg)
System.out.println(msg)
3
An Example from Scheme Nonnegative Integers
Semantics
The representation of n
(iszero? n) t n 0 f
n ? 0 (succ n) n1 (n 0) (pred n1)
n (n 0)
4
E.g., Silly Representation Items
Representation l l l d l l l
b _at_
5
An Example from Scheme Nonnegative Integers
Client implementation-independent
(define plus (lambda (x y) (if
(iszero? x) y (succ (plus
(pred x) y)))))
6
Nonnegative Integers Unary implementation
0 () n1 (cons t n) (define zero
'()) (define iszero? null?) (define succ (lambda
(n) (cons t n))) (define pred cdr)
7
Nonnegative Integers Ordinary implementation
(define zero 0 ) (define iszero? zero?) (define
succ (lambda (n) ( n 1))) (define pred (lambda
(n) (- n 1)))
Write a Comment
User Comments (0)
About PowerShow.com