data abstraction and modularity abstraction is the key principle to control the complexity...

30
Data Abstraction and Modularity abstraction is the key principle to control the complexity electro-physics transitor microprocessor operating system library user program boolean circuits machine instructions assembly language C Java, ML, Haskell B, Z, HOL, Isabelle specification

Upload: phillip-underwood

Post on 18-Jan-2016

225 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Data Abstraction and Modularity abstraction is the key principle to control the complexity electro-physics transitor microprocessor operating system library

Data Abstraction and Modularity

abstraction is the key principle tocontrol the complexity

electro-physics

transitor

microprocessor

operating system

library

user program

boolean circuits

machine instructions

assembly language

C

Java, ML, Haskell

B, Z, HOL, Isabellespecification

Page 2: Data Abstraction and Modularity abstraction is the key principle to control the complexity electro-physics transitor microprocessor operating system library

abstraction: 자세한 속사정을 감춘다는 의미 - fixed interface - implementation/representation-independence

Abstraction example: functional abstraction

- fixed interface: name and its type - implementation-independence add(x,y) sort(a)

Types are “the” language of interface

Page 3: Data Abstraction and Modularity abstraction is the key principle to control the complexity electro-physics transitor microprocessor operating system library

abstraction: 자세한 속사정을 감춘다는 의미 - fixed interface - implementation/representation-independence

Abstraction example: data abstractioninterface of int queue exception EmptyQ val emptyqueue: queue val enqueue: queue -> int -> queue val dequeue: queue -> int * queue

implementation of int queue exception EmptyQ let emptyqueue = ... let enqueue q n = ... let dequeue q = ...

Page 4: Data Abstraction and Modularity abstraction is the key principle to control the complexity electro-physics transitor microprocessor operating system library

interface of car val makeit: engine * size -> car val getin: car * animal -> car val getoff: car -> car val drive: car -> car

implementation of car let makeit(e,s) = ... let getin(c,a) = ... ...

Page 5: Data Abstraction and Modularity abstraction is the key principle to control the complexity electro-physics transitor microprocessor operating system library

Language Support for Data Abstraction

Use type-checking to enforce the separation: -abstract data type -module

* Type checking checks if every computationis done through the interface.

* Type checking checks if no informationother than the interface is assumed.

Page 6: Data Abstraction and Modularity abstraction is the key principle to control the complexity electro-physics transitor microprocessor operating system library

module Queue = struct type queue = T | N of int * queue let emptyqueue = T let enqueue q n = n::q let dequeue q = ...end

module type QUEUE = sig type queue val emptyqueue: queue val enqueue: queue -> int -> queue val dequeue: queue -> int * queueend

: QUEUE

In ML, done by signature matching

Page 7: Data Abstraction and Modularity abstraction is the key principle to control the complexity electro-physics transitor microprocessor operating system library

In C, pretended by .h and .c files

queue.h struct queue {...}; struct nqpair {...}; queue *emptyqueue; queue *enqueue(queue*, int); nqpair *dequeue(queue*); queue.c struct queue {...}; struct nqpair {...}; queue *emptyqueue {... }; queue *enqueue(queue* q, int x) {...}; nqpair *dequeue(queue* q) {...};

How to hide and check? 별드레게 무러바

Page 8: Data Abstraction and Modularity abstraction is the key principle to control the complexity electro-physics transitor microprocessor operating system library

Modules are more general thanabstract data type

- Modules are collection of definitions- Signatures are interfaces- Signature matching (wrapping modules by signatures) hides those not in the signature- Modules can be parameterized by modules/types

Remember the ML modules and module types

Page 9: Data Abstraction and Modularity abstraction is the key principle to control the complexity electro-physics transitor microprocessor operating system library

Language support for abstraction: - functional abstraction, data abstraction - abstract data type, module ML: module, module type, functor C++: class, class template Ada: package, generic package - type-system automaticallys checks if the programs violates the principle ML/Haskell: sound C++, Ada: not sound

Abstraction is the must in civilization.

Also true in computer science.

Also true in programming: - interface, implementation-independence

Page 10: Data Abstraction and Modularity abstraction is the key principle to control the complexity electro-physics transitor microprocessor operating system library

Object-Oriented Programming v.s.

Value-Oriented Programming

imperative v.s. applicative

물건중심기계중심명령형객체지향

값중심생각중심함수형

Two representative programming paradigms.What are they?

Page 11: Data Abstraction and Modularity abstraction is the key principle to control the complexity electro-physics transitor microprocessor operating system library

a := 1;b := 2;c := a + b;d := a + b;

1. c 의 3 이 d 의 3 과 같은가 ?2. a 를 바꾸면 c 도 바뀔까 ?3. d 를 바꾸면 c 도 바뀔까 ?4. e:=c 를 수행하면 c 를 복사해야하나 ?5. c 갖고 일 봤으면 , 그 3 을 없애도 되나 ?

싱거운 질문들

Page 12: Data Abstraction and Modularity abstraction is the key principle to control the complexity electro-physics transitor microprocessor operating system library

1. c 의 집합이 d 의 집합과 같은가 ?2. a 를 바꾸면 c 도 바뀔까 ?3. d 를 바꾸면 c 도 바뀔까 ?4. e:=c 를 수행하면 c 를 복사해야하나 ?5. c 갖고 일 봤으면 , 그 집합을 없애도 되나 ?

a := set(1,2,3);b := set(4,5,6);c := setUnion(a,b);d := setUnion(a,b);

아직도 싱거울까 ?정수보다는 복잡한 ( 컴퓨터에 구현할 때 하는일이 많은 ) 경우

Page 13: Data Abstraction and Modularity abstraction is the key principle to control the complexity electro-physics transitor microprocessor operating system library

항상 공유하도록 구현하는 방안

항상 복사하도록 구현하는 방안

두가지의 짬뽕

- 무조건 복사- 프로그램이해가 쉽다- 메모리 소모가 크다

- 얼키고 설키고- 버그없는 프로그램짜기 ?

- 물건이 변하지않게- 최대한 공유

Page 14: Data Abstraction and Modularity abstraction is the key principle to control the complexity electro-physics transitor microprocessor operating system library
Page 15: Data Abstraction and Modularity abstraction is the key principle to control the complexity electro-physics transitor microprocessor operating system library
Page 16: Data Abstraction and Modularity abstraction is the key principle to control the complexity electro-physics transitor microprocessor operating system library

fun eval(Var x, env, mem) = (entry env x, mem) | eval(Add(e,e’), env, mem) = let val (z, mem’) = eval(e, env, mem) val (z’, mem’’) = eval(e’, env, mem’) in (z+z’, mem’’) end | eval(Assign(x,e), env, mem) = let val (v,mem’) = eval(e, env, mem) val mem’’ = assign(mem’, x, v) in (v,mem’’) end

Page 17: Data Abstraction and Modularity abstraction is the key principle to control the complexity electro-physics transitor microprocessor operating system library
Page 18: Data Abstraction and Modularity abstraction is the key principle to control the complexity electro-physics transitor microprocessor operating system library
Page 19: Data Abstraction and Modularity abstraction is the key principle to control the complexity electro-physics transitor microprocessor operating system library
Page 20: Data Abstraction and Modularity abstraction is the key principle to control the complexity electro-physics transitor microprocessor operating system library
Page 21: Data Abstraction and Modularity abstraction is the key principle to control the complexity electro-physics transitor microprocessor operating system library
Page 22: Data Abstraction and Modularity abstraction is the key principle to control the complexity electro-physics transitor microprocessor operating system library
Page 23: Data Abstraction and Modularity abstraction is the key principle to control the complexity electro-physics transitor microprocessor operating system library
Page 24: Data Abstraction and Modularity abstraction is the key principle to control the complexity electro-physics transitor microprocessor operating system library
Page 25: Data Abstraction and Modularity abstraction is the key principle to control the complexity electro-physics transitor microprocessor operating system library
Page 26: Data Abstraction and Modularity abstraction is the key principle to control the complexity electro-physics transitor microprocessor operating system library
Page 27: Data Abstraction and Modularity abstraction is the key principle to control the complexity electro-physics transitor microprocessor operating system library
Page 28: Data Abstraction and Modularity abstraction is the key principle to control the complexity electro-physics transitor microprocessor operating system library
Page 29: Data Abstraction and Modularity abstraction is the key principle to control the complexity electro-physics transitor microprocessor operating system library
Page 30: Data Abstraction and Modularity abstraction is the key principle to control the complexity electro-physics transitor microprocessor operating system library